|
| 1 | +xk6-browser v0.5.0 is here! :tada: |
| 2 | + |
| 3 | +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/](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. |
| 4 | + |
| 5 | + |
| 6 | +## New Feature |
| 7 | + |
| 8 | +- Combining key presses when inputting text in an input field now works with the `Shift` modifier key ([#326](https://github.com/grafana/xk6-browser/pull/326), [#522](https://github.com/grafana/xk6-browser/pull/522)). |
| 9 | + |
| 10 | + ``` |
| 11 | + const l = page.locator('#input-text-test'); |
| 12 | + l.press('Shift+KeyH+i'); // "Hi" |
| 13 | + l.press('Backspace'); // "H" |
| 14 | + l.press('Backspace'); // "" |
| 15 | + l.press('KeyH+i'); // "hi" |
| 16 | + ``` |
| 17 | + |
| 18 | + |
| 19 | +## Bugs fixed |
| 20 | + |
| 21 | +- 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. |
| 22 | + ([#480](https://github.com/grafana/xk6-browser/pull/480), [#501](https://github.com/grafana/xk6-browser/pull/501)) |
| 23 | + |
| 24 | +- A `Page.waitForNavigation()` race condition, where the call would fail with a Go nil pointer dereference error. ([#500](https://github.com/grafana/xk6-browser/pull/500)) |
| 25 | + |
| 26 | + |
| 27 | +## Breaking changes |
| 28 | + |
| 29 | +- `chromium` is now an importable object, which changes the syntax for launching tests using Chromium (which is still the only supported browser type). ([#462](https://github.com/grafana/xk6-browser/pull/462), [#515](https://github.com/grafana/xk6-browser/pull/515)) |
| 30 | + |
| 31 | + Previously, scripts called `launch()` on the `k6/x/browser` module directly, and specified `'chromium'` as the first argument: |
| 32 | + ```js |
| 33 | + import launcher from 'k6/x/browser'; |
| 34 | + |
| 35 | + export default function () { |
| 36 | + const browser = launcher.launch('chromium', { |
| 37 | + headless: false, |
| 38 | + }); |
| 39 | + |
| 40 | + ... |
| 41 | + ``` |
| 42 | +
|
| 43 | + Now, `chromium` must be imported separately and `chromium.launch()` should be called instead: |
| 44 | + ```js |
| 45 | + import { chromium } from 'k6/x/browser'; |
| 46 | + |
| 47 | + export default function () { |
| 48 | + const browser = chromium.launch({ |
| 49 | + headless: false, |
| 50 | + }); |
| 51 | + |
| 52 | + ... |
| 53 | + ``` |
| 54 | +
|
| 55 | + The same options are supported in the `chromium.launch()` method as in the previous `launch()` function. |
| 56 | +
|
| 57 | +- `ElementHandle.click()` is now an asynchronous method that returns a Promise. ([#466](https://github.com/grafana/xk6-browser/pull/466)) |
| 58 | +
|
| 59 | + Note that the `async` and `await` keywords are not yet supported (see [this k6 issue](https://github.com/grafana/k6/issues/779) for a workaround), so resolving the Promise using `then()` is required for scripts to continue to work correctly. |
| 60 | +
|
| 61 | + See the [`fillform.js` example](https://github.com/grafana/xk6-browser/blob/v0.5.0/examples/fillform.js) for how to use it. |
| 62 | +
|
| 63 | +- `Page.waitForNavigation()` is now an asynchronous method that returns a Promise. ([#467](https://github.com/grafana/xk6-browser/pull/467)) |
| 64 | +
|
| 65 | + When expecting a navigation triggered by a `click()`, it's important to resolve both Promises inside a `Promise.all()` call, to avoid a race condition. |
| 66 | +
|
| 67 | + See the [`fillform.js` example](https://github.com/grafana/xk6-browser/blob/v0.5.0/examples/fillform.js) for how to use it. |
| 68 | +
|
| 69 | +- 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](https://github.com/grafana/xk6-browser/pull/508)) |
| 70 | +
|
| 71 | + This gives more flexibility, as you can handle this error however you prefer, including interrupting the iteration. For example: |
| 72 | +
|
| 73 | + ```js |
| 74 | + import { fail } from 'k6'; |
| 75 | + |
| 76 | + export default function () { |
| 77 | + ... |
| 78 | + |
| 79 | + Promise.all([ |
| 80 | + page.waitForNavigation({ timeout: 1000 }), |
| 81 | + page.locator('a').click(), |
| 82 | + ]).then(() => { |
| 83 | + // Everything went well, the page navigated. |
| 84 | + }, (err) => { |
| 85 | + console.log(err); // "waiting for navigation: timed out after 1s" |
| 86 | + fail(err); // interrupt the iteration |
| 87 | + }); |
| 88 | + ``` |
| 89 | +
|
| 90 | +
|
| 91 | +## Improvements |
| 92 | +
|
| 93 | +- We've made more changes to our log messages to make them more concise and user friendlier. ([#438](https://github.com/grafana/xk6-browser/pull/438)) |
| 94 | +
|
| 95 | +
|
| 96 | +## Internals |
| 97 | +
|
| 98 | +- Upgraded k6 dependency to v0.40.0. ([#523](https://github.com/grafana/xk6-browser/pull/523)) |
| 99 | +
|
| 100 | +- Several refactors to improve maintainability. |
| 101 | + ([#452](https://github.com/grafana/xk6-browser/pull/452), [#457](https://github.com/grafana/xk6-browser/pull/457), [#464](https://github.com/grafana/xk6-browser/pull/464), [#476](https://github.com/grafana/xk6-browser/pull/476), ([#497](https://github.com/grafana/xk6-browser/pull/497))) |
| 102 | +
|
| 103 | +- Add pprof server enabled by an optional environment variable. This will help us troubleshoot issues on a live xk6-browser process. ([#503](https://github.com/grafana/xk6-browser/pull/503), [#507](https://github.com/grafana/xk6-browser/pull/507)) |
0 commit comments