Skip to content

Commit a66f454

Browse files
committed
Browser best practices with async check
1 parent c9e0ceb commit a66f454

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/sources/next/using-k6-browser/recommended-practices/simulate-user-input-delay.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ In the browser modules there are various asynchronous APIs that can be used to w
5151

5252
```javascript
5353
import { browser } from 'k6/browser';
54-
import { check } from 'k6';
54+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
5555

5656
export const options = {
5757
scenarios: {
@@ -86,8 +86,9 @@ export default async function () {
8686
timeout: 2000,
8787
});
8888

89-
const innerHTML = await ok.innerHTML();
90-
check(ok, { 'waitForFunction successfully resolved': innerHTML == 'Hello' });
89+
await check(ok, {
90+
'waitForFunction successfully resolved': async () => await ok.innerHTML() == 'Hello'
91+
});
9192
} finally {
9293
await page.close();
9394
}
@@ -103,8 +104,8 @@ export default async function () {
103104
{{< code >}}
104105

105106
```javascript
106-
import { check } from 'k6';
107107
import { browser } from 'k6/browser';
108+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
108109

109110
export const options = {
110111
scenarios: {
@@ -147,8 +148,8 @@ It's important to call this in a [Promise.all](https://developer.mozilla.org/en-
147148
{{< code >}}
148149

149150
```javascript
150-
import { check } from 'k6';
151151
import { browser } from 'k6/browser';
152+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
152153

153154
export const options = {
154155
scenarios: {
@@ -176,7 +177,10 @@ export default async function () {
176177

177178
// The click action will start a navigation, and the waitForNavigation
178179
// will help the test wait until the navigation completes.
179-
await Promise.all([page.waitForNavigation(), submitButton.click()]);
180+
await Promise.all([
181+
page.waitForNavigation(),
182+
submitButton.click(),
183+
]);
180184
} finally {
181185
await page.close();
182186
}

0 commit comments

Comments
 (0)