Skip to content

fix(webdriverio): switchWindow supports exact window handle match#13857

Merged
christian-bromann merged 3 commits intowebdriverio:mainfrom
jan-molak:fix/switch-window-exact-handle-match
Nov 6, 2024
Merged

fix(webdriverio): switchWindow supports exact window handle match#13857
christian-bromann merged 3 commits intowebdriverio:mainfrom
jan-molak:fix/switch-window-exact-handle-match

Conversation

@jan-molak
Copy link
Contributor

This change enables browser.switchWindow(matcher) to accept an exact window handle and switch to it directly without cycling through all the open tabs.

Enables serenity-js/serenity-js#2572

Proposed changes

Serenity/JS offers a sophisticated API to allow developers to switch the active browser window to a desired one.

await actor.attemptsTo(
  Switch.to(Page.whichUrl(startsWith('https://github.com')))
)

Under the hood, Serenity/JS relies on the following WebdriverIO APIs:

  • browser.getWindowHandle
  • browser.getWindowHandles
  • browser.switchToWindow (deprecated)

However, switchToWindow(handle) is now deprecated, and the switchWindow(matcher) that replaces it does not currently support switching to the exact window handle Serenity/JS has found.

This change extends and improves the performance of browser.switchWindow(matcher) by making it exit early and avoid looping over the open window handles if:

  • the matcher is the current window handle
  • the matcher is one of the already open window handles

If there's no exact window handle match, the switchWindow function continues as before.

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

Discussed with @christian-bromann

This change enables browser.switchWindow(matcher) to accept an exact window handle and switch to it directly without cycling through all the open tabs.

Enables serenity-js/serenity-js#2572
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 5, 2024

Open in Stackblitz

eslint-plugin-wdio

pnpm add https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@13857

@wdio/allure-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@13857

@wdio/browser-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@13857

@wdio/appium-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@13857

@wdio/browserstack-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@13857

@wdio/cli

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@13857

@wdio/concise-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@13857

@wdio/config

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@13857

@wdio/cucumber-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@13857

@wdio/dot-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@13857

@wdio/firefox-profile-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@13857

@wdio/globals

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@13857

@wdio/jasmine-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@13857

@wdio/json-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@13857

@wdio/junit-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@13857

@wdio/lighthouse-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@13857

@wdio/local-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@13857

@wdio/logger

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@13857

@wdio/mocha-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@13857

@wdio/protocols

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@13857

@wdio/repl

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@13857

@wdio/reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@13857

@wdio/runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@13857

@wdio/sauce-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@13857

@wdio/shared-store-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@13857

@wdio/smoke-test-cjs-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@13857

@wdio/smoke-test-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@13857

@wdio/smoke-test-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@13857

@wdio/spec-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@13857

@wdio/static-server-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@13857

@wdio/sumologic-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@13857

@wdio/testingbot-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@13857

@wdio/types

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@13857

@wdio/utils

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@13857

@wdio/webdriver-mock-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@13857

webdriver

pnpm add https://pkg.pr.new/webdriverio/webdriverio/webdriver@13857

webdriverio

pnpm add https://pkg.pr.new/webdriverio/webdriverio@13857

commit: 56e263b

@jan-molak
Copy link
Contributor Author

jan-molak commented Nov 5, 2024

Looks like we have a couple of tests in the pipeline failing due to timeout issues that don't seem to be related to the proposed change.

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.

Thanks @jan-molak for the contribution!

Mind adding to the example a version where we switch to a window with a given handle?

@jan-molak
Copy link
Contributor Author

jan-molak commented Nov 6, 2024

Sure thing. Please hold off on merging for a moment. I just noticed something I'd like to fix.

By the way, pkg.pr.new is awesome 👍 I just pulled the packages it published into Serenity/JS test suite and picked up another bug.

@jan-molak
Copy link
Contributor Author

@christian-bromann - should be good to go I think

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Nov 6, 2024
@christian-bromann christian-bromann merged commit a7273a4 into webdriverio:main Nov 6, 2024
jan-molak added a commit to serenity-js/serenity-js that referenced this pull request Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants