Skip to content

fix(webdriverio): handle closeWindow for WDIO classic when no window is open#14050

Merged
christian-bromann merged 5 commits intowebdriverio:mainfrom
navin772:fix-wdio-closeWindow-classic
Jan 15, 2025
Merged

fix(webdriverio): handle closeWindow for WDIO classic when no window is open#14050
christian-bromann merged 5 commits intowebdriverio:mainfrom
navin772:fix-wdio-closeWindow-classic

Conversation

@navin772
Copy link
Contributor

Proposed changes

Fixes #14047

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Reviewers: @webdriverio/project-committers

@navin772
Copy link
Contributor Author

@christian-bromann I have made the changes as per your suggestions, PTAL.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 10, 2025

Open in Stackblitz

eslint-plugin-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@14050

@wdio/appium-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@14050

@wdio/allure-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@14050

@wdio/browser-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@14050

@wdio/browserstack-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@14050

@wdio/cli

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@14050

@wdio/concise-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@14050

@wdio/cucumber-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@14050

@wdio/config

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@14050

@wdio/dot-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@14050

@wdio/firefox-profile-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@14050

@wdio/globals

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@14050

@wdio/jasmine-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@14050

@wdio/json-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@14050

@wdio/junit-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@14050

@wdio/lighthouse-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@14050

@wdio/local-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@14050

@wdio/logger

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@14050

@wdio/mocha-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@14050

@wdio/protocols

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@14050

@wdio/repl

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@14050

@wdio/reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@14050

@wdio/runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@14050

@wdio/sauce-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@14050

@wdio/shared-store-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@14050

@wdio/smoke-test-cjs-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@14050

@wdio/smoke-test-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@14050

@wdio/smoke-test-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@14050

@wdio/spec-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@14050

@wdio/static-server-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@14050

@wdio/sumologic-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@14050

@wdio/testingbot-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@14050

@wdio/types

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@14050

@wdio/utils

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@14050

@wdio/webdriver-mock-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@14050

webdriver

npm i https://pkg.pr.new/webdriverio/webdriverio/webdriver@14050

webdriverio

npm i https://pkg.pr.new/webdriverio/webdriverio@14050

commit: 71d9a23

@navin772
Copy link
Contributor Author

@HannaTarasevich this fix should work to resolve the Malformed type for "handle" parameter of command switchToWindow error, but do note that the reproducible example you provided will still fail due to another error:

invalid session id: WebDriverError: invalid session id when running "url" with method "POST" and args "{"url":"https://the-internet.herokuapp.com/login"}"

since the window is being closed as soon as it is opened. You can try using above pkg.pr packages to test.

@HannaTarasevich
Copy link
Contributor

@navin772
Thank you for the prepared solution! Right, this error is totally expected

@christian-bromann
Copy link
Member

I am getting the following error with this:

2025-01-10T05:48:19.820Z INFO webdriver: COMMAND closeWindow()
2025-01-10T05:48:19.820Z INFO webdriver: [DELETE] http://localhost:58259/session/c6936cec45deca85bccc34e4f94c6222/window
2025-01-10T05:48:19.931Z INFO webdriver: RESULT []
2025-01-10T05:48:19.931Z INFO webdriver: COMMAND createWindow("tab")
2025-01-10T05:48:19.931Z INFO webdriver: [POST] http://localhost:58259/session/c6936cec45deca85bccc34e4f94c6222/window/new
2025-01-10T05:48:19.931Z INFO webdriver: DATA { type: 'tab' }
2025-01-10T05:48:19.946Z ERROR webdriver: WebDriverError: invalid session id when running "window/new" with method "POST" and args "{"type":"tab"}"
/Users/christian.bromann/Sites/WebdriverIO/projects/webdriverio/packages/webdriver../src/request/request.ts:228
        const error = new WebDriverResponseError(response, url, fullRequestOptions)
                      ^


invalid session id: WebDriverError: invalid session id when running "window/new" with method "POST" and args "{"type":"tab"}"

Basically the command to open the window fails - as expected since the driver closes the session as no windows are around anymore. I am not sure if this is a "solution" to the problem. I rather return a more conrete error message to the user notifying that they closed all windows.

What do you all think should be the right behavior?

@HannaTarasevich
Copy link
Contributor

This bug was only about a new issue with "malformed," which has been fixed. The "invalid session id" error was expected and has always worked this way. Therefore, I wouldn’t address it within the scope of this bug.

In general, I agree that the message could be improved, but I believe it is quite descriptive as it is now.

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@christian-bromann christian-bromann added the PR: Polish 💅 PRs that contain improvements on existing features label Jan 13, 2025
@christian-bromann christian-bromann merged commit 438c790 into webdriverio:main Jan 15, 2025
christian-bromann added a commit that referenced this pull request Jan 17, 2025
…w is open (#14050)

* fix `closeWindow` for WDIO classic

* log error instead of spawning new window as per W3C spec

* Update packages/webdriverio/src/session/context.ts

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Polish 💅 PRs that contain improvements on existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants