The check function not working while running a k6 browser-based load test version 0.52.
import { browser } from 'k6/browser';
import { check, sleep } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium'
}
}
}
},
thresholds: {
checks: ['rate==1.0']
}
};
export default async function () {
const page = await browser.newPage();
try {
// Navigate to the login page and wait until it's fully loaded
await page.goto('https://test.legalmatch.com', { waitUntil: 'load' });
console.log('Page loaded successfully');
// Click the Login text
const loginTextLocator = page.locator('.header__nav-item.top-menu__item.header__nav-item');
await loginTextLocator.waitFor();
console.log('Login text field found');
await loginTextLocator.click();
// Wait for the username field to be visible
await page.locator('#userName').fill('crisqatest01@outlook.com');
await page.locator('#password').fill('testqacris');
console.log('Credentials entered');
const submitButton = page.locator('input[value="Log In"]');
// Ensure submitButton exists before clicking
await submitButton.waitFor();
console.log('Submit button found');
// Ensure navigation finishes after login and the page fully loads
await Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle' }), // Wait until the page is fully loaded (network idle)
submitButton.click() // Trigger the click to submit the form
]);
console.log('Navigation after login completed');
// Sleep to ensure the page renders
sleep(5);
// Log current URL after login to check if navigation was successful
const currentURL = page.url();
console.log('Current URL after login:', currentURL);
// Additional logging: capture all visible text after login
const bodyText = await page.locator('body').textContent();
console.log('Body content after login:', bodyText);
// Try to locate "My Account" element
const successLocator = await page
.locator("div[class='cui-label cui-g-medium']")
.innerText();
const elementExists = await successLocator.waitFor({ timeout: 20000 }).catch(() => false);
if (elementExists) {
const loginSuccess = check(successLocator, {
'Login was successful': (successLocator) => successLocator == 'My Account'
});
console.log('Login success check:', loginSuccess);
} else {
console.error('Login success element not found');
}
} catch (error) {
console.error('Error during test execution:', error);
} finally {
// Close the page safely
if (page) {
try {
await page.close();
console.log('Page closed successfully');
} catch (closeError) {
console.warn('Failed to close the page:', closeError);
}
}
}
}
$ K6_BROWSER_HEADLESS=false k6 run test2.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: test2.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* ui: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
INFO[0014] Page loaded successfully source=console
INFO[0014] Login text field found source=console
WARN[0014] Request successful! browser_source=console-api source=browser
INFO[0016] Credentials entered source=console
INFO[0016] Submit button found source=console
INFO[0020] Navigation after login completed source=console
ERRO[0020] Error during test execution: {} source=console
INFO[0020] Page closed successfully source=console
browser_data_received.......: 11 MB 583 kB/s
browser_data_sent...........: 224 kB 12 kB/s
browser_http_req_duration...: avg=840.96ms min=90µs med=203.05ms max=6.2s p(90)=4.44s p(95)=5.3s
browser_http_req_failed.....: 0.00% ✓ 0 ✗ 242
browser_web_vital_cls.......: avg=0.007542 min=0.00166 med=0.007542 max=0.013424 p(90)=0.012247 p(95)=0.012835
browser_web_vital_fcp.......: avg=3.15s min=827.69ms med=1.87s max=6.75s p(90)=5.77s p(95)=6.26s
browser_web_vital_fid.......: avg=600µs min=400µs med=600µs max=800µs p(90)=760µs p(95)=780µs
browser_web_vital_inp.......: avg=8ms min=8ms med=8ms max=8ms p(90)=8ms p(95)=8ms
browser_web_vital_lcp.......: avg=3.06s min=827.69ms med=1.89s max=6.47s p(90)=5.55s p(95)=6.01s
browser_web_vital_ttfb......: avg=390.38ms min=198.7ms med=218.4ms max=1.07s p(90)=752.8ms p(95)=914.95ms
✓ checks......................: 0.00% ✓ 0 ✗ 0
data_received...............: 0 B 0 B/s
browser_web_vital_lcp.......: avg=3.06s min=827.69ms med=1.89s max=6.47s p(90)=5.55s p(95)=6.01s
browser_web_vital_ttfb......: avg=390.38ms min=198.7ms med=218.4ms max=1.07s p(90)=752.8ms p(95)=914.95ms
browser_web_vital_lcp.......: avg=3.06s min=827.69ms med=1.89s max=6.47s p(90)=5.55s p(95)=6.01s
browser_web_vital_lcp.......: avg=3.06s min=827.69ms med=1.89s max=6.47s p(90)=5.55s p(95)=6.01s
browser_web_vital_ttfb......: avg=390.38ms min=198.7ms med=218.4ms max=1.07s p(90)=752.8ms p(95)=914.95ms
✓ checks......................: 0.00% ✓ 0 ✗ 0
data_received...............: 0 B 0 B/s
data_sent...................: 0 B 0 B/s
iteration_duration..........: avg=17.52s min=17.52s med=17.52s max=17.52s p(90)=17.52s p(95)=17.52s
iterations..................: 1 0.052096/s
vus.........................: 1 min=1 max=1
vus_max.....................: 1 min=1 max=1
running (00m19.2s), 0/1 VUs, 1 complete and 0 interrupted iterations
ui ✓ [======================================] 1 VUs 00m19.2s/10m0s 1/1 shared iters