From 18eb2dd186ce78178845293f97873110cfcf0b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 27 Sep 2024 14:18:22 -0400 Subject: [PATCH] Update waitforfunction.js to async check --- examples/waitforfunction.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/waitforfunction.js b/examples/waitforfunction.js index d47973451..2816bceb0 100644 --- a/examples/waitforfunction.js +++ b/examples/waitforfunction.js @@ -1,5 +1,5 @@ -import { check } from 'k6'; import { browser } from 'k6/x/browser/async'; +import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { scenarios: { @@ -30,11 +30,16 @@ export default async function() { }, 1000); }); - const ok = await page.waitForFunction("document.querySelector('h1')", { - polling: 'mutation', - timeout: 2000, + await check(page, { + 'waitForFunction successfully resolved': + p => p.waitForFunction( + "document.querySelector('h1')", { + polling: 'mutation', + timeout: 2000 + }) + .then(e => e.innerHTML()) + .then(text => text == 'Hello') }); - check(ok, { 'waitForFunction successfully resolved': ok.innerHTML() == 'Hello' }); } finally { await page.close(); }