0

I am running into a strange problem with webdriverio/appium when trying to test an iOS app. The app has a WebView with a button labeled "Refresh". When I try to test for this button, I get a "not displayed" error (see code below).

it('should have the Refresh button', () => {
    WebViewScreen.waitForWebsiteLoaded();

    // Verify that Refresh button is displayed
    WebViewScreen.switchToContext(CONTEXT_REF.WEBVIEW);
    const button = $('button=Refresh');
    expect(button).toBeDisplayed();
    WebViewScreen.switchToContext(CONTEXT_REF.NATIVE);
});

Note that I am switching context to WEBVIEW before testing for the button. Looking at Appium logs, the request to find the button ($('button=Refresh')) is returning a 404. Tried a different selector: ['button[data-test="refresh-button"]'], but no go. I even put a browser.debug() and queried in the REPL - still 404 - although I can physically see the button on the screen!

I know that my webdriverio/appium setup is good because the exact same code works for another iOS screen with a WebView and a button - the only difference is the button name.

I have also ruled out the possibility that my selector is incorrect by going to the standalone webpage and testing for that button - no errors in this case! Here's the standalone web page code - only difference is no context switching calls:

it('should have the Refresh button', () => {
    browser.url('https://example.site.com/');

    // Verify that Refresh button is displayed
    const button = $('button=Refresh')
    expect(button).toBeDisplayed();
});

Any ideas on how to debug this? Are there any nuances about switching to WEBVIEW context that I am missing?

2 Answers 2

0

Finally got a breakthrough on this one - thanks to Alexi's suggestions on the Appium forum. Turns out that I had multiple WebViews in my app and I had to switch context to the right one. The trick is to set the fullContextList option on Appium to get more information about the available contexts, and then to select the right one.

0

What happens when you switch to regular webview

public static void switch(AppiumDriver driver) {
    Set<String> contextNames = driver.getContextHandles();
    for (String context : contextNames) {
        log.debug("Context available:{}", context);
        if (StringUtils.startsWithIgnoreCase(context, "WEBVIEW")) {
            log.debug("Switch to WEBVIEW");
            driver.context(context);

        }
1
  • Hi Johnny, please see my answer based on Alexi's suggestion. There were multiple WebViews and I had to make sure that I select the right one.
    – Naresh
    Commented Apr 3, 2020 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.