No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.47. Go to the latest version.

waitForFunction(pageFunction, arg[, options])

Returns when the pageFunction returns a truthy value.

ParameterTypeDefaultDescription
pageFunction
functionFunction to be evaluated in the page context.
arg
string''Optional argument to pass to pageFunction
options
objectnull

Returns

TypeDescription
Promise<JSHandle>The JSHandle instance associated with the page.

Example

import { browser } from 'k6/experimental/browser';
import { check } from 'k6';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}
export default async function () {
const page = browser.newPage();
try {
page.evaluate(() => {
setTimeout(() => {
const el = document.createElement('h1');
el.innerHTML = 'Hello';
document.body.appendChild(el);
}, 1000);
});
const ok = await page.waitForFunction("document.querySelector('h1')", {
polling: 'mutation',
timeout: 2000,
});
check(ok, { 'waitForFunction successfully resolved': ok.innerHTML() == 'Hello' });
} finally {
page.close();
}
}