No results for

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

waitForNavigation([options])

Waits for the given navigation lifecycle event to occur and returns the main resource response.

ParameterTypeDefaultDescription
options
objectnull

Events

attention

networkidle is DISCOURAGED. Don't use this method for testing especially with chatty websites where the event may never fire, rely on web assertions to assess readiness instead.

Events can be either:

  • 'domcontentloaded' - consider operation to be finished when the DOMContentLoaded event is fired.
  • 'load' - consider operation to be finished when the load event is fired.
  • 'networkidle' - Consider operation to be finished when there are no network connections for at least 500 ms.

Returns

TypeDescription
Promise<null | Response>The Response instance associated with the page. Else, it returns null

Example

import { chromium } from 'k6/experimental/browser';
import { check } from 'k6';
export default async function () {
const browser = chromium.launch({ headless: false });
const page = browser.newPage();
try {
await page.goto('https://test.k6.io/my_messages.php');
page.locator('input[name="login"]').type('admin');
page.locator('input[name="password"]').type('123');
const submitButton = page.locator('input[type="submit"]');
await Promise.all([page.waitForNavigation(), submitButton.click()])
check(page, {
'header': p => p.locator('h2').textContent() == 'Welcome, admin!',
});
} finally {
page.close();
browser.close();
}
}