@@ -34,12 +34,12 @@ The browser module predominantly provides asynchronous APIs, so it's best to avo
34
34
35
35
In the browser modules there are various asynchronous APIs that can be used to wait for certain states:
36
36
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. |
43
43
| [ page.waitForTimeout] ( #pagewaitfortimeout ) | Waits the given time. _ Use this instead of ` sleep ` in your frontend tests_ . |
44
44
45
45
## page.waitForFunction
@@ -52,7 +52,7 @@ In the browser modules there are various asynchronous APIs that can be used to w
52
52
53
53
``` javascript
54
54
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 ' ;
56
56
57
57
export const options = {
58
58
scenarios: {
@@ -87,8 +87,9 @@ export default async function () {
87
87
timeout: 2000 ,
88
88
});
89
89
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
+ });
92
93
} finally {
93
94
await page .close ();
94
95
}
@@ -104,7 +105,6 @@ export default async function () {
104
105
{{< code >}}
105
106
106
107
``` javascript
107
- import { check } from ' k6' ;
108
108
import { browser } from ' k6/browser' ;
109
109
110
110
export const options = {
@@ -148,7 +148,6 @@ It's important to call this in a [Promise.all](https://developer.mozilla.org/en-
148
148
{{< code >}}
149
149
150
150
``` javascript
151
- import { check } from ' k6' ;
152
151
import { browser } from ' k6/browser' ;
153
152
154
153
export const options = {
0 commit comments