import { chromium } from 'k6/experimental/browser';
import { check } from 'k6'
//XK6_BROWSER_LOG=trace K6_BROWSER_ENABLED=true k6 run Browser3.js
export default async function () {
const browser = chromium.launch({ headless: false });
const page = browser.newPage();
console.log("We are at 0!");
try {
console.log("We are at 1!");
await page.goto('https://search.apps-staging.epo.org/', { waitUntil: 'networkidle' });
console.log("We are at 2!");
await page.waitForTimeout(35000);
page.screenshot({ path: '../img/Credentials.png' });
console.log("We are at 3!");
await Promise.all([
page.waitForNavigation(),
//page.locator('input[type="submit"]').click(),
//page.screenshot({ path: '../img/Logon.png' }),
page.locator("//button[@data-testid='marker-search-button']").click(),
page.waitForSelector("//div[contains(@style, 'display: block;') and contains(@class, 'Spinner__spinner')]", {visible:false}),
]);
page.screenshot({ path: '../img/Log.png' });
check(page, {
'header': page.locator('h2').textContent() == 'Ansera',
});
} finally {
page.close();
browser.close();
}
}
in the logs i see we only ever reach We are at 1! We never reach INFO[0017] We are at 2!
I can see th browser opened and the page loads when i run the script, then browser just shuts down before we “We are at 2!”
I can see the following error in the logs
ERRO[0113] communicating with browser: read tcp 127.0.0.1:16261->127.0.0.1:16260: wsarecv: An existing connection was forcibly closed by the
remote host. category=cdp elapsed=“0 ms” goroutine=33
I’ve tried running your test script and it’s able to navigate to the website under test that is in the test script, and so I see We are at 2! in the console logs.
What OS are you running this script on?
Are you running it in Docker? If so which version of Docker?
The OS details are:
Edition Windows 10 Pro
Version 22H2
Installed on 29-06-2021
OS build 19045.2728
Experience Windows Feature Experience Pack 120.2212.4190.0
I have been playing with the script.
If i remove the //await page.waitForTimeout(15000); and replace it with a page.waitForNavigation(). The script proceeds to "We are at 3! " but fails with the following error when trying to click //button[@data-testid='marker-search-button. The browser is closed prematurely. The following error is logged:
Uncaught (in promise) GoError: clicking on “//button[@data-testid=‘marker-search-button’]”: getting new document handle: getting
document element handle: execution context changed; most likely because of a navigation
at reflect.methodValueCall (native)
at file:///D:/k6/scripts/k6/ansera/Ansera_TC1.js:24:6(57)
If i leave the await page.waitForTimeout(15000); then the script works.
I hadn’t noticed the await keyword on page.waitForTimeout(35000); and the page.waitForSelector in the promise.All. Currently the only browser async APIs are:
locator.click
elementHandle.click
frame.click
frame.goto
frame.waitForFunction
frame.waitForNavigation
page.click
page.goto
page.waitForFunction
page.waitForNavigation
page.setExtraHTTPHeaders
browser.on
locator.click
So using await or working with promises on any of the other APIs will not work as expected.
If you remove the await from page.waitForTimeout(35000); and move page.waitForSelector outside of promise.All, then hopefully it will work. I tried on a Windows 11 computer and i was able to get to “We are at 3!”. After that, it fails to locate //button[@data-testid='marker-search-button and times out.
The following scripts works for me:
try {
await page.goto(‘https://search.apps-staging.epo.org/’, { waitUntil: ‘networkidle’ });
page.waitForTimeout(15000);
page.screenshot({ path: ‘…/img/Start.png’ });
But if i remove the page.waitForTimeout(15000) the script will fail. Why is this? Shouldn’t await page.goto(‘https://search.apps-staging.epo.org/’, { waitUntil: ‘networkidle’ });
be sufficient? Obviously having a fied wait such as page.waitForTimeout is not ideal. The following script works in playwright without any page.waitForTimeout.
BTW. If i remove the page.waitForTimeout(15000) i get the following error
Uncaught (in promise) GoError: clicking on “//button[@data-testid=‘marker-search-button’]”: execution context changed; most likely because of a navigation
I tried the script you sent. But it shuts down prematurely at
page.locator(“//button[@data-testid=‘marker-search-button’]”).click(),
with the following error:
ERRO[0006] communicating with browser: read tcp 127.0.0.1:21236->127.0.0.1:21235: wsarecv: An existing connection was forcibly closed by the remote host. category=cdp elapsed=“75 ms” goroutine=61
ERRO[0006] process with PID 6404 unexpectedly ended: exit status 1 category=browser elapsed=“55 ms” goroutine=58