No results for

Powered byAlgolia
warning

This documentation is a work in progress, and some of the functionality that is listed below may not behave as expected.

Supported APIs

Examples

Fill out a form
import { check } from 'k6';
import { chromium } from 'k6/x/browser';
export default function() {
const browser = chromium.launch({
headless: false,
slowMo: '500ms' // slow down by 500ms
});
const context = browser.newContext();
const page = context.newPage();
// Goto front page, find login link and click it
page
.goto('https://test.k6.io/', { waitUntil: 'networkidle' })
.then(() => {
return Promise.all([
page.waitForNavigation(),
page.locator('a[href="/my_messages.php"]').click(),
]);
}).then(() => {
// Enter login credentials and login
page.locator('input[name="login"]').type('admin');
page.locator('input[name="password"]').type('123');
return Promise.all([
page.waitForNavigation(),
page.locator('input[type="submit"]').click(),
]);
}).then(() => {
check(page, {
'header': page.locator('h2').textContent() == 'Welcome, admin!',
});
}).finally(() => {
page.close();
browser.close();
});
}
Check element state
import { chromium } from 'k6/x/browser';
import { check } from 'k6';
export default function () {
const browser = chromium.launch({
headless: false,
});
const context = browser.newContext();
const page = context.newPage();
// Inject page content
page.setContent(`
<div class="visible">Hello world</div>
<div style="display:none" class="hidden"></div>
<div class="editable" editable>Edit me</div>
<input type="checkbox" enabled class="enabled">
<input type="checkbox" disabled class="disabled">
<input type="checkbox" checked class="checked">
<input type="checkbox" class="unchecked">
`);
// Check state
check(page, {
visible: (p) => p.$('.visible').isVisible(),
hidden: (p) => p.$('.hidden').isHidden(),
editable: (p) => p.$('.editable').isEditable(),
enabled: (p) => p.$('.enabled').isEnabled(),
disabled: (p) => p.$('.disabled').isDisabled(),
checked: (p) => p.$('.checked').isChecked(),
unchecked: (p) => p.$('.unchecked').isChecked() === false,
});
page.close();
browser.close();
}