Skip to content

[🐛 Bug]: closeWindow() leads to "Malformed type for "handle" parameter of command switchToWindow" error when only one window is opened #14047

@HannaTarasevich

Description

@HannaTarasevich

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

22.12.0

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

After the changes #14025, command closeWindow() leads to the error(when only one window has been opened):

[chrome 131.0.6778.205 windows #0-0] Error: Malformed type for "handle" parameter of command switchToWindow
[chrome 131.0.6778.205 windows #0-0] Error: Malformed type for "handle" parameter of command switchToWindow
[chrome 131.0.6778.205 windows #0-0] Expected: string
[chrome 131.0.6778.205 windows #0-0] Actual: undefined
[chrome 131.0.6778.205 windows #0-0]
[chrome 131.0.6778.205 windows #0-0] For more info see https://w3c.github.io/webdriver/#dfn-switch-to-window

It happens for both: Bidi and classic protocols ("wdio:enforceWebDriverClassic": true)

What is your expected behavior?

According to the documentation:
The Close Window command closes the current top-level browsing context. Once done, if there are no more top-level browsing contexts open, the WebDriver session itself is closed.

So the expected result is to close the window even if it was only one window, without the error (as before the fix)

How to reproduce the bug.

await browser.url(url)
await browser.closeWindow()

Relevant log output

[chrome 131.0.6778.205 windows #0-0] Error: Malformed type for "handle" parameter of command switchToWindow
[chrome 131.0.6778.205 windows #0-0] Error: Malformed type for "handle" parameter of command switchToWindow
[chrome 131.0.6778.205 windows #0-0] Expected: string
[chrome 131.0.6778.205 windows #0-0] Actual: undefined
[chrome 131.0.6778.205 windows #0-0]
[chrome 131.0.6778.205 windows #0-0] For more info see https://w3c.github.io/webdriver/#dfn-switch-to-window
[chrome 131.0.6778.205 windows #0-0]
[chrome 131.0.6778.205 windows #0-0]     at Browser.protocolCommand (file:///C:/123123/node_modules/webdriver/build/node.js:86:15)
[chrome 131.0.6778.205 windows #0-0]     at Browser.wrapCommandFn (C:\123123\node_modules\@wdio\utils\build\index.js:893:32)
[chrome 131.0.6778.205 windows #0-0]     at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
[chrome 131.0.6778.205 windows #0-0]

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockedIssues that are blocked due to certain circumstancesBug 🐛

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions