webdriverio: [đ Bug]: Certain methods (waitForDisplayed, isElementDisplayed, etc...) are not working after switching to NATIVE_APP context
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
9.5.7
Node.js Version
20.11.1
Mode
WDIO Testrunner
Which capabilities are you using?
What happened?
I came across the following problem after upgrading to WDIO 9 from WDIO 7.
Starting the automation of a mobile device (what I tried were Android Emulator and iOS Simulator) with âbrowserNameâ specified in capabilities, then switching to the NATIVE_APP context with driver.switchContext('NATIVE_APP') then trying to explicitly wait for components with element.waitForDisplayer() or element.isDisplayed(), etc will display an error message and wonât run properly. (See Relevant Log Output section for the message.)
However, starting the automation in the NATIVE_APP context (by not specifying a âbrowserNameâ in the capabilities) will run properly, even if you switch to a WEBVIEW context and then back to NATIVE_CONTEXT.
What is your expected behavior?
The test should be able to call the methods as it did in WDIO 7 and execute without an issue.
How to reproduce the bug.
The issue can be easily reproduced. I have used the latest appium-boilerplate and stripped it down to a smaller âprojectâ, so I can share it: https://github.com/FieryHammer/wdio9-native-app-context-issue-demo
Clone the repository, and install the dependencies with npm install (you can see, everything should be the latest version for the time being). Set up emulators as you would with appium-installer.
You can find 4 WDIO configs:
wdio.android.browser.conf.tsSets up an Android emulator with Chrome as the browser so that the default context will be a WEBVIEW contextwdio.android.native.conf.tsSets up an Android emulator without âbrowserNameâ so that the default context will be NATIVE_APP contextwdio.ios.browser.conf.tsSets up an iOS simulator with Safari as the browser so that the default context will be a WEBVIEW contextwdio.ios.native.conf.tsSets up an iOS simulator without âbrowserNameâ so that the default context will be NATIVE_APP context
The appropriate package.json scripts to run these tests are android.browser, android.native, ios.browser, and ios.native.
The â*.nativeâ scripts will programmatically open a browser app (Safari on iOS and Chrome on Android), then navigate to https://webdriver.io, select the âGet Startedâ button, wait for it, and click it. These tests should run as intended.
The â*browserâ scripts will automatically open their configured browsers, navigate to https://webdriver.io once again, switch to the âNATIVE_APPâ context, try to select the âGet Startedâ button, wait for it, and click it. This will throw error messages when the waitForDisplayed is called.
Relevant log output
WARN webdriver: WebDriverError: Method is not implemented when running "execute/sync" with method "POST" and args "function isElementDisplayed(element) {
[0-0] function nodeIsElement(node) {
[0-0] if (!node) {
[0-0] return false;
[0-0] }
[0-0] switch (node.nodeType) {
[0-0] case Node.ELEMENT_NODE:
[0-0] case Node.DOCUMENT_NODE:
[0-0] case Node.DOCUMENT_FRAGMENT_NODE:
[0-0] return true;
[0-0] default:
[0-0] return false;
[0-0] }
[0-0] }
[0-0] function parentElementForElement(element2) {
[0-0] if (!element2) {
[0-0] return null;
[0-0] }
[0-0] return enclosingNodeOrSelfMatchingPredicate(element2.parentNode, nodeIsElement);
[0-0] }
[0-0] function enclosingNodeOrSelfMatchingPredicate(targetNode, predicate) {
[0-0] for (let node = targetNode; node && node !== targetNode.ownerDocument; node = node.parentNode) {
[0-0] if (predicate(node)) {
[0-0] return node;
[0-0] }
[0-0] }
[0-0] return null;
[0-0] }
[0-0] function enclosingElementOrSelfMatchingPredicate(targetElement, predicate) {
[0-0] for (let element2 = targetElement; element2 && element2 !== targetElement.ownerDocument; element2 = parentElementForElement(element2)) {
[0-0] if (predicate(element2)) {
[0-0] return element2;
[0-0] }
[0-0] }
[0-0] return null;
[0-0] }
[0-0] function cascadedStylePropertyForElement(element2, property) {
[0-0] if (!element2 || !property) {
[0-0] return null;
[0-0] }
[0-0] if ("ShadowRoot" in window && element2 instanceof window.ShadowRoot) {
[0-0] element2 = element2.host;
[0-0] }
[0-0] const computedStyle = window.getComputedStyle(element2);
[0-0] const computedStyleProperty = computedStyle.getPropertyValue(property);
[0-0] if (computedStyleProperty && computedStyleProperty !== "inherit") {
[0-0] return computedStyleProperty;
[0-0] }
[0-0] const parentElement = parentElementForElement(element2);
[0-0] return cascadedStylePropertyForElement(parentElement, property);
[0-0] }
[0-0] function elementHasBoundingBox(element2) {
[0-0] const boundingBox = element2.getBoundingClientRect();
[0-0] return boundingBox.width > 0 && boundingBox.height > 0;
[0-0] }
[0-0] function elementSubtreeHasNonZeroDimensions(element2) {
[0-0] if (elementHasBoundingBox(element2)) {
[0-0] return true;
[0-0] }
[0-0] const boundingBox = element2.getBoundingClientRect();
[0-0] if (element2.tagName.toUpperCase() === "PATH" && boundingBox.width + boundingBox.height > 0) {
[0-0] const strokeWidth = cascadedStylePropertyForElement(element2, "stroke-width");
[0-0] return !!strokeWidth && parseInt(strokeWidth, 10) > 0;
[0-0] }
[0-0] const cascadedOverflow = cascadedStylePropertyForElement(element2, "overflow");
[0-0] if (cascadedOverflow === "hidden") {
[0-0] return false;
[0-0] }
[0-0] return [].some.call(element2.childNodes, function(childNode) {
[0-0] if (childNode.nodeType === Node.TEXT_NODE) {
[0-0] return true;
[0-0] }
[0-0] if (nodeIsElement(childNode)) {
[0-0] return elementSubtreeHasNonZeroDimensions(childNode);
[0-0] }
[0-0] return false;
[0-0] });
[0-0] }
[0-0] function elementOverflowsContainer(element2) {
[0-0] const cascadedOverflow = cascadedStylePropertyForElement(element2, "overflow");
[0-0] if (cascadedOverflow !== "hidden") {
[0-0] return false;
[0-0] }
[0-0] return true;
[0-0] }
[0-0] function isElementSubtreeHiddenByOverflow(element2) {
[0-0] if (!element2) {
[0-0] return false;
[0-0] }
[0-0] if (!elementOverflowsContainer(element2)) {
[0-0] return false;
[0-0] }
[0-0] if (!element2.childNodes.length) {
[0-0] return false;
[0-0] }
[0-0] return [].every.call(element2.childNodes, function(childNode) {
[0-0] if (childNode.nodeType === Node.TEXT_NODE) {
[0-0] return false;
[0-0] }
[0-0] if (!nodeIsElement(childNode)) {
[0-0] return true;
[0-0] }
[0-0] if (!elementSubtreeHasNonZeroDimensions(childNode)) {
[0-0] return true;
[0-0] }
[0-0] return isElementSubtreeHiddenByOverflow(childNode);
[0-0] });
[0-0] }
[0-0] function isElementInsideShadowRoot(element2) {
[0-0] if (!element2) {
[0-0] return false;
[0-0] }
[0-0] if (element2.parentNode && element2.parentNode.host) {
[0-0] return true;
[0-0] }
[0-0] return isElementInsideShadowRoot(element2.parentNode);
[0-0] }
[0-0] if (!isElementInsideShadowRoot(element) && // IE doesn't support document.contains, therefor check before using
[0-0] (typeof document.contains === "function" ? !document.contains(element) : !document.body.contains(element))) {
[0-0] return false;
[0-0] }
[0-0] switch (element.tagName.toUpperCase()) {
[0-0] case "BODY":
[0-0] return true;
[0-0] case "SCRIPT":
[0-0] case "NOSCRIPT":
[0-0] return false;
[0-0] case "OPTGROUP":
[0-0] case "OPTION": {
[0-0] const enclosingSelectElement = enclosingNodeOrSelfMatchingPredicate(element, function(e) {
[0-0] return e.tagName.toUpperCase() === "SELECT";
[0-0] });
[0-0] return isElementDisplayed(enclosingSelectElement);
[0-0] }
[0-0] case "INPUT":
[0-0] if (element.type === "hidden") {
[0-0] return false;
[0-0] }
[0-0] break;
[0-0] // case 'MAP':
[0-0] // FIXME: Selenium has special handling for <map> elements. We don't do anything now.
[0-0] default:
[0-0] break;
[0-0] }
[0-0] if (cascadedStylePropertyForElement(element, "visibility") !== "visible") {
[0-0] return false;
[0-0] }
[0-0] const hasAncestorWithZeroOpacity = !!enclosingElementOrSelfMatchingPredicate(element, function(e) {
[0-0] return Number(cascadedStylePropertyForElement(e, "opacity")) === 0;
[0-0] });
[0-0] const hasAncestorWithDisplayNone = !!enclosingElementOrSelfMatchingPredicate(element, function(e) {
[0-0] return cascadedStylePropertyForElement(e, "display") === "none";
[0-0] });
[0-0] if (hasAncestorWithZeroOpacity || hasAncestorWithDisplayNone) {
[0-0] return false;
[0-0] }
[0-0] if (!elementSubtreeHasNonZeroDimensions(element)) {
[0-0] return false;
[0-0] }
[0-0] if (isElementSubtreeHiddenByOverflow(element) && !elementHasBoundingBox(element)) {
[0-0] return false;
[0-0] }
[0-0] return true;
[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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (9 by maintainers)
@wswebcreation created the issue now, unfortunately cannot share much form my repo but happy to help you with testing the solution, thanks đ https://github.com/webdriverio/webdriverio/issues/14258
In case this is helpful: After bumping the versions to 9.6.0, the tests still break, but the error message is now different. Instead of indicating that âwaitForDisplayedâ is unimplemented, it now shows âcheckVisibilityâ being unimplementd (the code is still calling waitForDisplayed):