xk6-browser v0.5.0 is here! 🎉
This minor release contains a new feature, a few important stability fixes, some breaking changes, improvements, and a continuation of our efforts to migrate to async APIs. Coinciding with this release, is the up-to-date documentation, which can be found at https://k6.io/docs/javascript-api/xk6-browser/. Only a few of the most used classes like Browser
and BrowserContext
are currently well documented, and we're working hard on updating the rest of the API.
New Feature
-
Combining key presses when inputting text in an input field now works with the
Shift
modifier key (#326, #522).const l = page.locator('#input-text-test'); l.press('Shift+KeyH+i'); // "Hi" l.press('Backspace'); // "H" l.press('Backspace'); // "" l.press('KeyH+i'); // "hi"
Bugs fixed
-
A couple of
Page.goto()
race conditions, where the call would timeout waiting for the navigation event. This was mainly found to occur in CI, but it could happen in real world tests as well.
(#480, #501) -
A
Page.waitForNavigation()
race condition, where the call would fail with a Go nil pointer dereference error. (#500)
Breaking changes
-
chromium
is now an importable object, which changes the syntax for launching tests using Chromium (which is still the only supported browser type). (#462, #515)Previously, scripts called
launch()
on thek6/x/browser
module directly, and specified'chromium'
as the first argument:import launcher from 'k6/x/browser'; export default function () { const browser = launcher.launch('chromium', { headless: false, }); ...
Now,
chromium
must be imported separately andchromium.launch()
should be called instead:import { chromium } from 'k6/x/browser'; export default function () { const browser = chromium.launch({ headless: false, }); ...
The same options are supported in the
chromium.launch()
method as in the previouslaunch()
function. -
ElementHandle.click()
is now an asynchronous method that returns a Promise. (#466)Note that the
async
andawait
keywords are not yet supported (see this k6 issue for a workaround), so resolving the Promise usingthen()
is required for scripts to continue to work correctly.See the
fillform.js
example for how to use it. -
Page.waitForNavigation()
is now an asynchronous method that returns a Promise. (#467)When expecting a navigation triggered by a
click()
, it's important to resolve both Promises inside aPromise.all()
call, to avoid a race condition.See the
fillform.js
example for how to use it. -
As part of the
Page.waitForNavigation()
async change, a timeout error won't interrupt the script iteration anymore, and the Promise will be rejected instead. (#508)This gives more flexibility, as you can handle this error however you prefer, including interrupting the iteration. For example:
import { fail } from 'k6'; export default function () { ... Promise.all([ page.waitForNavigation({ timeout: 1000 }), page.locator('a').click(), ]).then(() => { // Everything went well, the page navigated. }, (err) => { console.log(err); // "waiting for navigation: timed out after 1s" fail(err); // interrupt the iteration });
Improvements
- We've made more changes to our log messages to make them more concise and user friendlier. (#438)