Skip to content

Commit c9e0ceb

Browse files
committed
Running browser tests with async check
1 parent 9593c5e commit c9e0ceb

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ To avoid timing errors or other race conditions in your script, if you have acti
228228
{{< code >}}
229229
230230
```javascript
231-
import { check } from 'k6';
232231
import { browser } from 'k6/browser';
232+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
233233
234234
export const options = {
235235
scenarios: {
@@ -258,11 +258,13 @@ export default async function () {
258258
259259
const submitButton = page.locator('input[type="submit"]');
260260
261-
await Promise.all([page.waitForNavigation(), submitButton.click()]);
261+
await Promise.all([
262+
page.waitForNavigation(),
263+
submitButton.click(),
264+
]);
262265
263-
const header = await page.locator('h2').textContent();
264-
check(header, {
265-
header: (h) => h == 'Welcome, admin!',
266+
await check(page.locator('h2'), {
267+
'header': async lo => await lo.textContent() == 'Welcome, admin!'
266268
});
267269
} finally {
268270
await page.close();
@@ -296,7 +298,7 @@ Keep in mind that there is an additional performance overhead when it comes to s
296298
297299
```javascript
298300
import { browser } from 'k6/browser';
299-
import { check } from 'k6';
301+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
300302
import http from 'k6/http';
301303
302304
export const options = {
@@ -329,9 +331,9 @@ export async function browserTest() {
329331
330332
await page.locator('#checkbox1').check();
331333
332-
const info = await page.locator('#checkbox-info-display').textContent();
333-
check(info, {
334-
'checkbox is checked': (info) => info === 'Thanks for checking the box',
334+
await check(page.locator('#checkbox-info-display'), {
335+
'checkbox is checked': async lo =>
336+
await lo.textContent() === 'Thanks for checking the box'
335337
});
336338
} finally {
337339
await page.close();

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ To avoid timing errors or other race conditions in your script, if you have acti
228228
{{< code >}}
229229
230230
```javascript
231-
import { check } from 'k6';
232231
import { browser } from 'k6/browser';
232+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
233233
234234
export const options = {
235235
scenarios: {
@@ -258,11 +258,13 @@ export default async function () {
258258
259259
const submitButton = page.locator('input[type="submit"]');
260260
261-
await Promise.all([page.waitForNavigation(), submitButton.click()]);
261+
await Promise.all([
262+
page.waitForNavigation(),
263+
submitButton.click(),
264+
]);
262265
263-
const header = await page.locator('h2').textContent();
264-
check(header, {
265-
header: (h) => h == 'Welcome, admin!',
266+
await check(page.locator('h2'), {
267+
'header': async lo => await lo.textContent() == 'Welcome, admin!'
266268
});
267269
} finally {
268270
await page.close();
@@ -296,7 +298,7 @@ Keep in mind that there is an additional performance overhead when it comes to s
296298
297299
```javascript
298300
import { browser } from 'k6/browser';
299-
import { check } from 'k6';
301+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
300302
import http from 'k6/http';
301303
302304
export const options = {
@@ -329,9 +331,9 @@ export async function browserTest() {
329331
330332
await page.locator('#checkbox1').check();
331333
332-
const info = await page.locator('#checkbox-info-display').textContent();
333-
check(info, {
334-
'checkbox is checked': (info) => info === 'Thanks for checking the box',
334+
await check(page.locator('#checkbox-info-display'), {
335+
'checkbox is checked': async lo =>
336+
await lo.textContent() === 'Thanks for checking the box'
335337
});
336338
} finally {
337339
await page.close();

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ To avoid timing errors or other race conditions in your script, if you have acti
228228
{{< code >}}
229229
230230
```javascript
231-
import { check } from 'k6';
232231
import { browser } from 'k6/browser';
232+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
233233
234234
export const options = {
235235
scenarios: {
@@ -258,11 +258,13 @@ export default async function () {
258258
259259
const submitButton = page.locator('input[type="submit"]');
260260
261-
await Promise.all([page.waitForNavigation(), submitButton.click()]);
261+
await Promise.all([
262+
page.waitForNavigation(),
263+
submitButton.click(),
264+
]);
262265
263-
const header = await page.locator('h2').textContent();
264-
check(header, {
265-
header: (h) => h == 'Welcome, admin!',
266+
await check(page.locator('h2'), {
267+
'header': async lo => await lo.textContent() == 'Welcome, admin!'
266268
});
267269
} finally {
268270
await page.close();
@@ -296,7 +298,7 @@ Keep in mind that there is an additional performance overhead when it comes to s
296298
297299
```javascript
298300
import { browser } from 'k6/browser';
299-
import { check } from 'k6';
301+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
300302
import http from 'k6/http';
301303
302304
export const options = {
@@ -329,9 +331,9 @@ export async function browserTest() {
329331
330332
await page.locator('#checkbox1').check();
331333
332-
const info = await page.locator('#checkbox-info-display').textContent();
333-
check(info, {
334-
'checkbox is checked': (info) => info === 'Thanks for checking the box',
334+
await check(page.locator('#checkbox-info-display'), {
335+
'checkbox is checked': async lo =>
336+
await lo.textContent() === 'Thanks for checking the box'
335337
});
336338
} finally {
337339
await page.close();

0 commit comments

Comments
 (0)