Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit a0a453d

Browse files
committed
Update waitforfunction.js to async check
1 parent 671b263 commit a0a453d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

examples/waitforfunction.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { check } from 'k6';
21
import { browser } from 'k6/x/browser/async';
2+
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
33

44
export const options = {
55
scenarios: {
@@ -30,11 +30,16 @@ export default async function() {
3030
}, 1000);
3131
});
3232

33-
const ok = await page.waitForFunction("document.querySelector('h1')", {
34-
polling: 'mutation',
35-
timeout: 2000,
33+
await check(page, {
34+
'waitForFunction successfully resolved':
35+
p => p.waitForFunction(
36+
"document.querySelector('h1')", {
37+
polling: 'mutation',
38+
timeout: 2000
39+
})
40+
.then(e => e.innerHTML())
41+
.then(text => text == 'Hello')
3642
});
37-
check(ok, { 'waitForFunction successfully resolved': ok.innerHTML() == 'Hello' });
3843
} finally {
3944
await page.close();
4045
}

0 commit comments

Comments
 (0)