Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the k6 browser JS example
Browse files Browse the repository at this point in the history
inancgumus committed Jun 11, 2024

Verified

This commit was signed with the committer’s verified signature.
inancgumus İnanç Gümüş
1 parent 1e6e62b commit 9a58bb5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions examples/experimental/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { check } from 'k6';
import { browser } from 'k6/experimental/browser';
import { browser } from 'k6/browser';

export const options = {
scenarios: {
@@ -18,8 +18,8 @@ export const options = {
}

export default async function() {
const context = browser.newContext();
const page = context.newPage();
const context = await browser.newContext();
const page = await context.newPage();

try {
// Goto front page, find login link and click it
@@ -29,19 +29,20 @@ export default async function() {
page.locator('a[href="/my_messages.php"]').click(),
]);
// Enter login credentials and login
page.locator('input[name="login"]').type('admin');
page.locator('input[name="password"]').type('123');
await page.locator('input[name="login"]').type("admin");
await page.locator('input[name="password"]').type("123");
// We expect the form submission to trigger a navigation, so to prevent a
// race condition, setup a waiter concurrently while waiting for the click
// to resolve.
await Promise.all([
page.waitForNavigation(),
page.locator('input[type="submit"]').click(),
]);
check(page, {
'header': p => p.locator('h2').textContent() == 'Welcome, admin!',
const content = await page.locator("h2").textContent();
check(content, {
'header': content => content == 'Welcome, admin!',
});
} finally {
page.close();
await page.close();
}
}

0 comments on commit 9a58bb5

Please sign in to comment.