Skip to content

Commit 3f48e1e

Browse files
Update Browser API migration to async note (#1638)
* Update Browser API migration to async note * Style fix --------- Co-authored-by: Heitor Tashiro Sergent <[email protected]>
1 parent e4d9c60 commit 3f48e1e

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

docs/sources/next/using-k6-browser/running-browser-tests.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ To run a simple local script:
7070

7171
{{% admonition type="note" %}}
7272

73-
To provide rough compatibility with the Playwright API, the browser module API is also being converted from synchronous to asynchronous. `page.goto()` is now asynchronous so `await` keyword is used to deal with the asynchronous nature of the operation.
73+
Starting from v0.52.0 the browser module API has been converted to an asynchronous API. That means that most of the methods now return promises. Refer to the [migration guide](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/migrating-to-k6-v0-52/) to learn more about the changes and how to update your scripts.
7474

7575
{{% /admonition %}}
7676

@@ -257,21 +257,18 @@ export default async function () {
257257
const page = await browser.newPage();
258258
259259
try {
260-
await page.goto("https://test.k6.io/my_messages.php");
260+
await page.goto('https://test.k6.io/my_messages.php');
261261
262-
await page.locator('input[name="login"]').type("admin");
263-
await page.locator('input[name="password"]').type("123");
262+
await page.locator('input[name="login"]').type('admin');
263+
await page.locator('input[name="password"]').type('123');
264264
265265
const submitButton = page.locator('input[type="submit"]');
266266
267-
await Promise.all([
268-
page.waitForNavigation(),
269-
submitButton.click(),
270-
]);
267+
await Promise.all([page.waitForNavigation(), submitButton.click()]);
271268
272-
const header = await page.locator("h2").textContent();
269+
const header = await page.locator('h2').textContent();
273270
check(header, {
274-
header: h => h == "Welcome, admin!",
271+
header: (h) => h == 'Welcome, admin!',
275272
});
276273
} finally {
277274
await page.close();
@@ -340,7 +337,7 @@ export async function browserTest() {
340337
341338
const info = await page.locator('#counter-button').textContent();
342339
check(info, {
343-
'checkbox is checked': info => info === 'Thanks for checking the box',
340+
'checkbox is checked': (info) => info === 'Thanks for checking the box',
344341
});
345342
} finally {
346343
await page.close();

docs/sources/v0.52.x/using-k6-browser/running-browser-tests.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ To run a simple local script:
7070

7171
{{% admonition type="note" %}}
7272

73-
To provide rough compatibility with the Playwright API, the browser module API is also being converted from synchronous to asynchronous. `page.goto()` is now asynchronous so `await` keyword is used to deal with the asynchronous nature of the operation.
73+
Starting from v0.52.0 the browser module API has been converted to an asynchronous API. That means that most of the methods now return promises. Refer to the [migration guide](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/migrating-to-k6-v0-52/) to learn more about the changes and how to update your scripts.
7474

7575
{{% /admonition %}}
7676

@@ -257,21 +257,18 @@ export default async function () {
257257
const page = await browser.newPage();
258258
259259
try {
260-
await page.goto("https://test.k6.io/my_messages.php");
260+
await page.goto('https://test.k6.io/my_messages.php');
261261
262-
await page.locator('input[name="login"]').type("admin");
263-
await page.locator('input[name="password"]').type("123");
262+
await page.locator('input[name="login"]').type('admin');
263+
await page.locator('input[name="password"]').type('123');
264264
265265
const submitButton = page.locator('input[type="submit"]');
266266
267-
await Promise.all([
268-
page.waitForNavigation(),
269-
submitButton.click(),
270-
]);
267+
await Promise.all([page.waitForNavigation(), submitButton.click()]);
271268
272-
const header = await page.locator("h2").textContent();
269+
const header = await page.locator('h2').textContent();
273270
check(header, {
274-
header: h => h == "Welcome, admin!",
271+
header: (h) => h == 'Welcome, admin!',
275272
});
276273
} finally {
277274
await page.close();
@@ -340,7 +337,7 @@ export async function browserTest() {
340337
341338
const info = await page.locator('#counter-button').textContent();
342339
check(info, {
343-
'checkbox is checked': info => info === 'Thanks for checking the box',
340+
'checkbox is checked': (info) => info === 'Thanks for checking the box',
344341
});
345342
} finally {
346343
await page.close();

0 commit comments

Comments
 (0)