Hi all.
I’m currently experiencing this error. Moreover, I cannot reproduce it as it is randomly occurred.
Uncaught (in promise) GoError: getting page URL: evaluating JS: Cannot find context with specified id running at github.com/grafana/xk6-browser/common.(*Page).URL-fm (native)
And the code of the error can be seen below.
const waitingRoundThreshold = 60;
let currentWaitingRound = 0;
while ((await page.url()) !== urlStr)) { // Here is where the error occurred.
if (currentWaitingRound > waitingRoundThreshold) {
fail("Page did not load within 60 seconds. This iteration has been halted.");
}
console.log("Waiting for the page to be loaded...");
currentWaitingRound++;
sleep(1); // Wait for 1 second and check again
}
const checkbox1 = page.locator('#checkbox1');
const checkbox2 = page.locator('#checkbox2');
const checkbox3 = page.locator('#checkbox3');
console.log("Waiting for all checkboxes to visible.");
await checkbox1.waitFor({ state: 'visible' });
await checkbox2.waitFor({ state: 'visible' });
await checkbox3.waitFor({ state: 'visible' });
if (await checkbox1.isVisible() &&
await checkbox2.isVisible() &&
await checkbox3.isVisible()
) {
console.log("Check all the checkboxes.");
await checkbox1.click({ force: true });
await checkbox2.click({ force: true });
await checkbox3.click({ force: true });
}
const nextButtonSelector = '#nextBtn';
await Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle' }),
page.locator(nextButtonSelector ).waitFor({ state: 'visible' }),
console.log("Click next button"),
page.locator(nextButtonSelector ).click()
]);
As you can see, it’s a super simple script that wait for the checkbox to show up and then checking on it and proceed to the next step.
This code is working most of the time, but somehow it was managed to randomly show the error that I mentioned above, which cause the end of the iteration.
I found this error since I was starting test the script on the test runner that I was hosted on the cloud instance as it runs on multiple VUs, but this issue is not about running the test on the cloud because I also experiencing this error while I’m working on the script on the local with 1 VU and 1 iteration on shared-iteration mode, so this issue is clearly about the script itself, not the environment.
For the testing site, it was located behind the Cloudflare firewall as it is a dev site, so before testing it we need to add the tester IP address to its whitelist, so that the tester can access the site.
The question is, what is the possible root cause for this issue? is it because the script, or the site that we test might be having some mechanism that possible trigger this error?
Thank you!