Skip to content

Commit 093dc65

Browse files
committed
Update to use async check in examples
1 parent 404b5d9 commit 093dc65

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

docs/sources/v0.52.x/using-k6-browser/recommended-practices/simulate-user-input-delay.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ The browser module predominantly provides asynchronous APIs, so it's best to avo
3434

3535
In the browser modules there are various asynchronous APIs that can be used to wait for certain states:
3636

37-
| Method | Description |
38-
| ------------------------------------------------ | ----------------------------------------------------------------------------- |
39-
| [page.waitForFunction](#pagewaitforfunction) | Waits for the given function to return a truthy value. |
40-
| [page.waitForLoadState](#pagewaitforloadstate) | Waits for the specified page life cycle event. |
41-
| [page.waitForNavigation](#pagewaitfornavigation) | Waits for the navigation to complete after one starts. |
42-
| [locator.waitFor](#locatorwaitfor) | Wait for the element to be in a particular state. |
37+
| Method | Description |
38+
| ------------------------------------------------ | --------------------------------------------------------------------------- |
39+
| [page.waitForFunction](#pagewaitforfunction) | Waits for the given function to return a truthy value. |
40+
| [page.waitForLoadState](#pagewaitforloadstate) | Waits for the specified page life cycle event. |
41+
| [page.waitForNavigation](#pagewaitfornavigation) | Waits for the navigation to complete after one starts. |
42+
| [locator.waitFor](#locatorwaitfor) | Wait for the element to be in a particular state. |
4343
| [page.waitForTimeout](#pagewaitfortimeout) | Waits the given time. _Use this instead of `sleep` in your frontend tests_. |
4444

4545
## page.waitForFunction
@@ -52,7 +52,7 @@ In the browser modules there are various asynchronous APIs that can be used to w
5252

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

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

90-
const innerHTML = await ok.innerHTML();
91-
check(ok, { 'waitForFunction successfully resolved': innerHTML == 'Hello' });
90+
await check(ok, {
91+
'waitForFunction successfully resolved': async (ok) => (await ok.innerHTML()) == 'Hello',
92+
});
9293
} finally {
9394
await page.close();
9495
}
@@ -104,7 +105,6 @@ export default async function () {
104105
{{< code >}}
105106

106107
```javascript
107-
import { check } from 'k6';
108108
import { browser } from 'k6/browser';
109109

110110
export const options = {
@@ -148,7 +148,6 @@ It's important to call this in a [Promise.all](https://developer.mozilla.org/en-
148148
{{< code >}}
149149

150150
```javascript
151-
import { check } from 'k6';
152151
import { browser } from 'k6/browser';
153152

154153
export const options = {

docs/sources/v0.53.x/using-k6-browser/recommended-practices/simulate-user-input-delay.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ In the browser modules there are various asynchronous APIs that can be used to w
5252

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

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

90-
const innerHTML = await ok.innerHTML();
91-
check(ok, { 'waitForFunction successfully resolved': innerHTML == 'Hello' });
90+
await check(ok, {
91+
'waitForFunction successfully resolved': async (ok) => (await ok.innerHTML()) == 'Hello',
92+
});
9293
} finally {
9394
await page.close();
9495
}
@@ -104,7 +105,6 @@ export default async function () {
104105
{{< code >}}
105106

106107
```javascript
107-
import { check } from 'k6';
108108
import { browser } from 'k6/browser';
109109

110110
export const options = {
@@ -148,7 +148,6 @@ It's important to call this in a [Promise.all](https://developer.mozilla.org/en-
148148
{{< code >}}
149149

150150
```javascript
151-
import { check } from 'k6';
152151
import { browser } from 'k6/browser';
153152

154153
export const options = {

0 commit comments

Comments
 (0)