-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
browser.js
41 lines (38 loc) · 1.18 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { check } from 'k6';
import { chromium } from 'k6/experimental/browser';
export const options = {
thresholds: {
checks: ["rate==1.0"]
}
}
export default async function() {
const browser = chromium.launch({
headless: __ENV.XK6_HEADLESS ? true : false,
});
const context = browser.newContext();
const page = context.newPage();
try {
// Goto front page, find login link and click it
await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
await Promise.all([
page.waitForNavigation(),
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');
// 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': page.locator('h2').textContent() == 'Welcome, admin!',
});
} finally {
page.close();
browser.close();
}
}