I have written a simple test with K6 browser – it logs into a website and then brings up a sequential series of pages.
It seems to work, but no matter what I do the browser closes at 30 seconds, causing all remaining actions to fail. I’ve spent time searching on the web and in the documentation, and I haven’t figured out a way around it. Perhaps it is related to the gracefulStop parameter, but it complains about an unknown option when placed in options.
I’m sure there is something very silly that I’m overlooking, but I’ve been banging my head against this for several hours and have not made any progress.
Thanks in advance for any assistance that can be offered!
Can you try returning promise after clicking on login. I have written script as below and it works-
export function webtest() {
const browser = chromium.launch({
args: [], // Extra commandline arguments to include when launching browser process
debug: true, // Log all CDP messages to k6 logging subsystem
devtools: true, // Open up developer tools in the browser by default
env: {}, // Environment variables to set before launching browser process
executablePath: null, // Override search for browser executable in favor of specified absolute path
headless: true, // Show browser UI or not
ignoreDefaultArgs: [], // Ignore any of the default arguments included when launching browser process
proxy: {}, // Specify to set browser's proxy config
slowMo: '1000ms', // Slow down input actions and navigations by specified time
timeout: '60s', // Default timeout to use for various actions and navigations
});
const page = browser.newPage();
page.goto(Utils.getBaseUrl() , { waitUntil: 'load' }).
then(() => {
page.locator(selectors.loginPage.username).type('')
page.locator(selectors.loginPage.password).type('')
return Promise.all([
page.waitForNavigation(),
page.locator(loginBtn).click()
]).then(() => {
page.screenshot({ path: 'screenshots/01_login.png' }),
page.waitForSelector(""),
page.locator("").type('')
page.waitForSelector('')
return Promise.all([
page.waitForNavigation(),
page.locator("").click()
])
}).then(() => {
page.waitForSelector(""),
check(page, {
'Patient Page': page.locator("").textContent() == '',
});
page.screenshot({ path: 'screenshots/02.png' })
}).finally(() => {
page.close();
browser.close();
})
})
I’m a backend developer – not a front end one – but I think I’ve done what you’ve suggested, and the browser is still always forcibly closing at 30 seconds. (In fact, things seems to get a little worse, in that the script stops loading pages after the third one and just waits for the forcible close!)
Has anyone seen a browser stay up longer than a 30 second run time? If so, would they be willing to share the script?
Can you have one more try, seems you havnt return promise at correct place
export function webtest() {
const browser = chromium.launch({
args: [], // Extra commandline arguments to include when launching browser process
debug: true, // Log all CDP messages to k6 logging subsystem
devtools: true, // Open up developer tools in the browser by default
env: {}, // Environment variables to set before launching browser process
executablePath: null, // Override search for browser executable in favor of specified absolute path
headless: true, // Show browser UI or not
ignoreDefaultArgs: [], // Ignore any of the default arguments included when launching browser process
proxy: {}, // Specify to set browser's proxy config
slowMo: '1000ms', // Slow down input actions and navigations by specified time
timeout: '60s', // Default timeout to use for various actions and navigations
});
const page = browser.newPage();
page
.goto(`${host_port}${url}`, { waitUntil: "networkidle" })
.then(() => {
page.locator('input[name="inputusername"]').type(username),
page.locator('input[name="inputpassword"]').type([password]),
page.screenshot({ path: "login-screenshot.png" })
return Promise.all([
page.waitForNavigation(),
page.locator('//button[text()=" Login"]').click(),
]).then(() => {
url = "/r/apps/assets";
console.log(`Bringing up ${url}`);
page.goto(`${host_port}${url}`, { waitUntil: "networkidle" })
.then(() => {
page.screenshot({ path: "assets-screenshot.png" })
})
}).then(() => {
url = "/r/apps/assets";
console.log(`Bringing up ${url}`);
page.goto(`${host_port}${url}`, { waitUntil: "networkidle" })
.then(() => {
page.screenshot({ path: "assets-screenshot.png" })
})
}).finally(() => {
page.close();
browser.close();
})
})
Hi @ankur I need also the browser keeps open to completely test the end2end scenario unfortunately on the next page the browser will suddenly close. You may replicate below script.
Thanks for the test script. I was able to replicate the issue on my side too.
What’s happening is that the test is timing out after 30 seconds. In the latest version of k6, there is still a bug where a timeout on the BrowserType (chromium) is used globally, when it’s only meant to be used for the launch or connect methods on chromium. For now the fix is to set a higher timeout (60s worked for me):
ERRO[0020] communicating with browser: read tcp 127.0.0.1:61913->127.0.0.1:61912: wsarecv: An existing connection was forcibly closed by the remote host. category=cdp elapsed="0 ms" goroutine=87
ERRO[0020] process with PID 24232 unexpectedly ended: exit status 1 category=browser elapsed="43 ms" goroutine=84 5)=641.19ms
The issue has been resolve by setting a higher timeout then I can proceed to end to end load test at the last page.
✓ Should be at Homepage
✓ Should be at Subcategory Page
✓ Should be at Description Page
✓ Should be at Save Your Case Page
✓ Should be at Cost Estimate Page
✓ Case should be posted!
ERRO[0100] communicating with browser: read tcp 127.0.0.1:61397->127.0.0.1:61396: wsarecv: An existing connection was forcibly closed by the remote host. category=cdp elapsed="73351 ms" goroutine=27
ERRO[0100] cleaning up the user data directory: remove C:\Users\LMPH\AppData\Local\Temp\xk6-browser-data-4251929022\Default\Affiliation Database: The process cannot access the file because it is being used by another process. category="BrowserType:Launch" elapsed="77 ms" goroutine=74
running (01m39.5s), 0/1 VUs, 1 complete and 0 interrupted iterations
browser ✓ [======================================] 1 VUs 01m39.5s/10m0s 1/1 iters, 1 per VU
running (01m39.5s), 0/1 VUs, 1 complete and 0 interrupted iterations
browser ✓ [======================================] 1 VUs 01m39.5s/10m0s 1/1 iters, 1 per VU
ERRO[0100] process with PID 28956 unexpectedly ended: exit status 1 category=browser elapsed="5 ms" goroutine=24