grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
343 stars 41 forks source link

`BrowserContext` timeout is more lenient than in PW #445

Closed ankur22 closed 11 months ago

ankur22 commented 2 years ago

Tested against: dbede120c63df43995813a847a25b0e66e289592

If you run the following scripts then you should find that the PW script fails with a timeout error, whereas the xk6-browser script succeeds.

xk6-browser Script:

import { sleep } from 'k6';
import launcher from 'k6/x/browser';

export default function () {
  const browser = launcher.launch('chromium', {
      headless: false,
  });
  const context = browser.newContext();
  const page = context.newPage();
  context.setDefaultNavigationTimeout(1);
  const res = page.goto('https://maps.google.com');

  sleep(10);
  browser.close();
}

PW script:

// @ts-check
const { test, chromium } = require('@playwright/test');

test.describe('Editing', () => {
  test('Type login creds', async () => {
    const browser = await chromium.launch({ headless: false, slowMo: 500 });
    const ctx = await browser.newContext();
    const page = await ctx.newPage();
    ctx.setDefaultNavigationTimeout(1);
    await page.goto('https://maps.google.com');

    await new Promise(resolve => setTimeout(resolve, 10000));

    await browser.close();
  });
});
ankur22 commented 11 months ago

This issue was fixed with https://github.com/grafana/xk6-browser/pull/1035. I've tested the changes with the latest version of main (86329fbb36f04c962073298c25233553a952e4f9) and the following script and the test times out as expected, unlike the previous behaviour where it didn't time out:

import { browser } from 'k6/experimental/browser';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      iterations: 1,
      options: {
        browser: {
          type: 'chromium'
        },
      },
    },
  },
}

export default async function () {
  const page = browser.newPage();
  const context = browser.context();
  context.setDefaultNavigationTimeout(1);

  page.goto('https://maps.google.com');

  page.close();
}