Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kajmagnus/75f091bb12be830e81dcba246c2634da to your computer and use it in GitHub Desktop.
Save kajmagnus/75f091bb12be830e81dcba246c2634da to your computer and use it in GitHub Desktop.
Hi WebdriverIO! Here're the test files to reproduce the bug, well on my laptop at least:
$ cat wdio-get-win-handles-main.html
<style>
body {
background: #111;
color: #ddd;
}
</style>
<body>
<p>Hi there
</p>
<p><a href="./wdio-get-win-handles-popup.html" target="_blank">Open popup</a>
</p>
<p>It closes itself after 3 seconds.
</p>
</body>
20:22:29 64 ~/dev/test/bugrepros/wdio-win-handles$
20:22:39 64 ~/dev/test/bugrepros/wdio-win-handles$
20:22:39 64 ~/dev/test/bugrepros/wdio-win-handles$ cat wdio-get-win-handles-popup.html
<head>
<script>
setTimeout(function() {
console.log("Bye bye, 3 seconds elapsed");
window.close();
}, 3000);
</script>
</head>
<body>
<p>Hello, nice to see you.
<br><br>
</p>
<p>Want to login?</p>
<p>... 3 seconds</p>
<p>Bye bye</p>
</body>
20:22:41 65 ~/dev/test/bugrepros/wdio-win-handles$
20:22:42 65 ~/dev/test/bugrepros/wdio-win-handles$
20:22:42 65 ~/dev/test/bugrepros/wdio-win-handles$ cat wdio-get-win-handles-self-closing-window.test.js
describe("WebdriverIO getWindowHandles() works with self closing windows", () => {
let mainWinHandle;
let startMs;
let numHandles;
it("Open a page with a popup _target=blank link", () => {
browser.navigateTo("http://localhost:8080/wdio-get-win-handles-main.html")
mainWinHandle = browser.getWindowHandle();
});
it("Open the popup", () => {
console.log(`mainWinHandle: ${mainWinHandle}`);
console.log(`Opening login popup`);
startMs = Date.now();
browser.$('a').click();
});
it("Switch to the popup win", () => {
const allHandles = browser.getWindowHandles();
console.log(`allHandles: ${JSON.stringify(allHandles)}`);
numHandles = allHandles.length;
if (numHandles !== 2)
throw Error(`Bad num handles: ${numHandles}`);
const popupHandle = allHandles[0] === mainWinHandle ? allHandles[1] : allHandles[0];
console.log(`browser.switchToWindow('${popupHandle}');`);
browser.switchToWindow(popupHandle);
});
it("Call browser.getWindowHandles() until after the popup has closed itself", () => {
let elapsedMs = 0;
while (elapsedMs < 6*1000 || numHandles >= 2) {
browser.pause(400);
elapsedMs = Date.now() - startMs;
console.log(`browser.getWindowHandles(), millis elapsed: ${Date.now() - startMs}`);
numHandles = browser.getWindowHandles().length; // <—— this blocks, after popup closed itself
}
});
it("This didn't hang wdio forever", () => {
console.log(`Hello I'm still here`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment