Closed gavvvr closed 1 week ago
It seems like the issue is caused by the for
loop implemented in switchWindow
, which uses this.switchToWindow(tab)
to cycle through all the windows until it finds the one accepted by the matcher.
If the requested window is not found, finishing the loop will leave the context focused on the latest available window, and lead to the unexpected behaviour described by @gavvvr.
@jan-molak yeah, I saw this :) The fix is already coming ...
Thanks for taking a stab at this @gavvvr 👏
Have you read the Contributing Guidelines on issues?
WebdriverIO Version
v9.2.1
Node.js Version
v22.6.0
Mode
Standalone Mode
Which capabilities are you using?
What happened?
Initially, I though it's a problem of wdio-electron-service (see webdriverio-community/wdio-electron-service#762), and formulated it differently. Today I've spent some time debugging the code, understood that it's a problem of webdriverio and came up to the following observation:
switchWindow
for some window, which is not known, WDIO throws exception (expected), but switched the window to the latest available (not expected side effect)What is your expected behavior?
The window switch is not expected, if invalid window was requested from
switchWindow()
How to reproduce the bug.
Consider the simplest possible E2E browser testing project generated with
npm init wdio@latest .
Here is the test scenario:
Relevant log output
Code of Conduct
Is there an existing issue for this?