No results for

Powered byAlgolia

⚠️ Compatibility

The xk6-browser API aims for rough compatibility with the Playwright API for NodeJS.

Because k6 does not run in NodeJS, the xk6-browser API will slightly differ from its Playwright counterpart.

Note that k6 APIs are synchronous.

Supported APIs

MethodPlaywright Relevant Distinctions
page.bringToFront()-
page.check(selector[, options])-
page.click(selector[, options])-
page.close([options])-
page.content()-
page.context()-
page.dblclick(selector[, options])-
page.dispatchEvent(selector, type[, eventInit, options])-
page.emulateMedia([options])-
page.evaluate(pageFunction[, arg])-
page.evaluateHandle(pageFunction[, arg])-
page.fill(selector, value[, options])-
page.focus(selector[, options])-
page.frames()-
page.getAttribute(selector, name[, options])-
page.goto(url[, options])-
page.hover(selector[, options])-
page.innerHTML(selector[, options])-
page.innerText(selector[, options])-
page.inputValue(selector[, options])-
page.isChecked(selector[, options])-
page.isClosed()-
page.isDisabled(selector[, options])-
page.isEditable(selector[, options])-
page.isEnabled(selector[, options])-
page.isHidden(selector[, options])-
page.isVisible(selector[, options])-
page.mainFrame()-
page.opener()-
page.press(selector, key[, options])-
page.reload([options])-
page.screenshot([options])-
page.selectOption(selector, values[, options])-
page.setChecked(selector, checked[, options])-
page.setContent(html[, options])-
page.setDefaultNavigationTimeout(timeout)-
page.setDefaultTimeout(timeout)-
page.setExtraHTTPHeaders(headers)-
page.setInputFiles(selector, files[, options])-
page.setViewportSize(viewportSize)-
page.tap(selector[, options])-
page.textContent(selector[, options])-
page.title()-
page.type(selector, text[, options])-
page.uncheck(selector[, options])-
page.unroute(url[, handler])-
page.url()-
page.viewportSize()-
page.waitForFunction(pageFunction[, arg, options])-
page.waitForLoadState([state, options])-
page.waitForNavigation([options])-
page.waitForRequest(urlOrPredicate[, options])-
page.waitForResponse(urlOrPredicate[, options])-
page.waitForSelector(selector[, options])-
page.waitForTimeout(timeout)-
keyboard-
mouse-
touchscreen-

Missing Playwright APIs

The next APIs depends on event-loop support in k6:

🚧 xk6-browser is in beta - we are working to cover more Playwright APIs.

Examples

import launcher from 'k6/x/browser';
export default function () {
const browser = launcher.launch('chromium', {
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' });
const elem = page.$('a[href="/my_messages.php"]');
elem.click();
// Enter login credentials and login
page.$('input[name="login"]').type('admin');
page.$('input[name="password"]').type('123');
page.$('input[type="submit"]').click();
// Wait for next page to load
page.waitForLoadState('networkdidle');
page.close();
browser.close();
}

Browser-level APIs