Skip to content

fix(webdriverio): don't fail if getContext is not supported#13950

Merged
christian-bromann merged 4 commits intomainfrom
cb/getContext-fallback
Dec 11, 2024
Merged

fix(webdriverio): don't fail if getContext is not supported#13950
christian-bromann merged 4 commits intomainfrom
cb/getContext-fallback

Conversation

@christian-bromann
Copy link
Member

Proposed changes

We've had folks reporting that they get an error like this:

aaaaa

This patch mitigates this problem by just catching this error.

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

n/a

Reviewers: @webdriverio/project-committers

@christian-bromann christian-bromann added the PR: Polish 💅 PRs that contain improvements on existing features label Dec 6, 2024
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 6, 2024

Open in Stackblitz

eslint-plugin-wdio

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

@wdio/appium-service

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

@wdio/browser-runner

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

@wdio/allure-reporter

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

@wdio/browserstack-service

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

@wdio/cli

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

@wdio/concise-reporter

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

@wdio/config

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

@wdio/cucumber-framework

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

@wdio/firefox-profile-service

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

@wdio/dot-reporter

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

@wdio/globals

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

@wdio/jasmine-framework

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

@wdio/json-reporter

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

@wdio/junit-reporter

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

@wdio/lighthouse-service

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

@wdio/local-runner

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

@wdio/logger

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

@wdio/mocha-framework

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

@wdio/protocols

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

@wdio/repl

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

@wdio/reporter

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

@wdio/runner

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

@wdio/sauce-service

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

@wdio/shared-store-service

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

@wdio/smoke-test-cjs-service

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

@wdio/smoke-test-reporter

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

@wdio/smoke-test-service

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

@wdio/spec-reporter

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

@wdio/static-server-service

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

@wdio/sumologic-reporter

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

@wdio/testingbot-service

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

@wdio/types

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

@wdio/utils

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

@wdio/webdriver-mock-service

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

webdriver

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

webdriverio

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

commit: 619e47d

Copy link
Member

@wswebcreation wswebcreation left a comment

Choose a reason for hiding this comment

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

Hi @christian-bromann , see my comment

context : typeof context === 'object' ?
context.id :
undefined
const context = await this.#browser.getContext().catch((err) => {
Copy link
Member

Choose a reason for hiding this comment

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

@christian-bromann

Do you also have the context of when this happens, this is not something that should occur when using Appium, unless they are for example

  • using wrong caps/WDIO gets back non W3C ones
  • the driver is old as ...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think generally we can't make the assumption that just because a driver is considered as "mobile" they have the getContext command implemented. A driver can always fail to send the correct capabilities causing WebdriverIO to consider a session as mobile when it isn't. This patch will continue to log and elevate the problem but won't cause the whole session to fail.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

So my two-cents:
We then might need to:

  • Fix the isMobile check to make it more robust
  • Do this "fallback" for all commands

I also believe we can't "patch" the vendors (because this doesn't seem to be a specific Appium issue, unless a very old driver is used) if they don't return "valid" W3C responses.

Copy link
Member Author

Choose a reason for hiding this comment

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

  • Fix the isMobile check to make it more robust

We should totally strive for that but unfortunately can't rely on vendors implementing the specifications correctly.

  • Do this "fallback" for all commands

What do you mean by "all commands"? If some one uses an unsupported command in their test, it should fail. However with these session manager (e.g. context, shadow root manager or the polyfill manager) we are enhancing WebdriverIO in the background and these things shouldn't cause the testrun to fail. Hence this patch which makes the context manager do nothing if getContext is not implemented.

if they don't return "valid" W3C responses.

I think this is not the issue. The issue is that the command is not implemented by the vendor or WebDriver server in which case we should disable the context manager.

Copy link
Member

@wswebcreation wswebcreation Dec 9, 2024

Choose a reason for hiding this comment

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

What do you mean by "all commands"? If some one uses an unsupported command

I mean for mobile commands specific commands. But I agree with what you say

I think this is not the issue. The issue is that the command is not implemented by the vendor or WebDriver server in which case we should disable the context manager.

I believe you just fixed this "not implemented by WebDriver" with #13949, so I wonder if this "fix" is still needed. I would then still let it fail and throw a different error message (maybe throw the capabilities that are used) to determine which drivers are not supporting this. Appium drivers (especially the most used ones) should support the "browser" commands AND the "native" commands. getContext is one of the oldest API's
Regarding the vendors, from what I now see LT is doing it differently, they default to JSONWP

image

and the W3C caps are not "Appium" proof

image

I'll put checking the vendors on my todo list so we can properly check if it's mobile based on the correct caps

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe you just fixed this "not implemented by WebDriver" with #13949, so I wonder if this "fix" is still needed.

I put up this patch because I am afraid we run into more issues where our mobile capability detection fails and causes a failure with the whole test run. I think this patch makes sense no matter what because we just disable the context manager in case the command fails.

Copy link
Member

Choose a reason for hiding this comment

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

I believe you just fixed this "not implemented by WebDriver" with #13949, so I wonder if this "fix" is still needed.

I put up this patch because I am afraid we run into more issues where our mobile capability detection fails and causes a failure with the whole test run. I think this patch makes sense no matter what because we just disable the context manager in case the command fails.

Then can you add extra logs for debugging purposes so we can update the logic that is behind this when we get issues?

Copy link
Member Author

@christian-bromann christian-bromann Dec 10, 2024

Choose a reason for hiding this comment

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

What would you suggest aside from the

log.warn(`Error getting context: ${err}`)

?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe also throw the requested capabilities so we can determine if the mobile checks have made an error

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@wswebcreation wswebcreation left a comment

Choose a reason for hiding this comment

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

Thanks!

@christian-bromann christian-bromann merged commit 7e90730 into main Dec 11, 2024
@christian-bromann christian-bromann deleted the cb/getContext-fallback branch December 11, 2024 19:51
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.

2 participants