Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add custom network throttling in playwright-lighthouse package #43

Open
iamAfrontendDev opened this issue Feb 11, 2023 · 0 comments

Comments

@iamAfrontendDev
Copy link

I want to add network throttling 3g config in the playwright-lighthouse package, I don't know where exactly to pass the config, even though I am running a CDP session I don't see a difference in lighthouse metrics report when run on slow 3g, the results are same as in default network condition, as the lighthouse itself uses some simulation throttling so do not know how to override that, as the requirement is to run the test case in different network conditions and see if there are differences in performances metrics of lighthouse report when run on different network conditions.

test('lighthouse playwright metrics uisng slow 3g network condition', async ({ playwright }) => {
  const browser = await playwright.chromium.launch({
    args: ['--remote-debugging-port=9223'],
  });
  const context = await browser.newContext();
  const pageNum = await context.newPage();
  const cdpSession = await context.newCDPSession(pageNum);

  await cdpSession.send('Network.emulateNetworkConditions',{
  offline:false,
  downloadThroughput: ((500 * 1000) / 8) * 0.8,
  uploadThroughput: ((500 * 1000) / 8) * 0.8,
  latency: 400 * 5,
});

  await pageNum.goto(HOME_PAGE_URL, { waitUntil: 'networkidle' });
  const report = await playAudit({
    page: pageNum,
    thresholds: {
      performance: 50,
    },
    reports: {
      formats: { html: true },
      name: 'playwright-lighthouse-report slow 3g',
      directory: './e2e/playwright-lighthouse-report-' + Date.now().toString(),
    },
    port: 9223,
  });

  expect(report.lhr.audits['cumulative-layout-shift'].numericValue).toBeLessThan(CUMULATIVE_LAYOUT_SHIFT);
  expect(report.lhr.audits['first-contentful-paint'].numericValue).toBeLessThan(FIRST_CONTENTFUL_PAINT_THRESHOLD);
  expect(report.lhr.audits['speed-index'].numericValue).toBeLessThan(SPEED_INDEX_THRESHOLD);
  expect(report.lhr.audits['largest-contentful-paint'].numericValue).toBeLessThan(LARGEST_CONTENTFUL_PAINT_THRESHOLD);
  expect(report.lhr.audits['interactive'].numericValue).toBeLessThan(TIME_TO_INTERACTIVE_THRESHOLD);
  expect(report.lhr.audits['max-potential-fid'].numericValue).toBeLessThan(FIRST_INPUT_DELAY_THRESHOLD);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant