0

I'm running Appium on Mac to test an Android Native App directly on an Android device. However, when I try to fetch the contexts and switch to the one containing WEBVIEW (When I use UIAutomator or Chrome DevelopTool Inspector, It do exist named as android.webkit.WebView), But when I try todriver.switch_to.context('WEBVIEW') it gives me No Context... only returns one context, NATIVE_APP.

When I use the inspector, I'm able to see a WebView and a lot of View children appended to it, which relate to each one of the elements inside the app. So, despite it doesn't show the element tree in Web view mode, I'm able to see it's using a WebView, but somehow isn't able to connect to that specific context. enter image description here

I find some guy provide that change the desire_capability['automationName']='Selendroid' it does not work for me due to my other native elements could not be found any longer if it changes.

platform : Android
version : 5.1.1
device: real android device

Any ideas about this, please?

Kent
  • 71
  • 1
  • 10
  • 1
    Can you post UIAutomator's screen shot of your WebView screen – Vinod Oct 10 '16 at 04:07
  • @Vinod Hi, I have post a question on github also, there is detail description on that. https://github.com/appium/appium/issues/6973 – Kent Oct 12 '16 at 05:11
  • Can you put some wait before do driver.getContextHandles(); and chech whether you are still getting only NATIVE_VIEW – Vinod Oct 12 '16 at 05:17
  • @Vinod I have the code below: ` time.sleep(5) driver.switch_to.context("WEBVIEW") driver.switch_to.context("NATIVE_APP") time.sleep(1)` while I look into the Appium log the `[debug] [AndroidDriver] Found webviews: [] [debug] [AndroidDriver] Available contexts: ["NATIVE_APP"] `while actually the WEBVIEW does exist. – Kent Oct 12 '16 at 09:07
  • Is the webview debugging enabled ?? for appium to work webview debugging should be enabled from Developer – krishna chetan Oct 12 '16 at 09:28
  • @krishnachetan Do you mean that if the webview debugging is set to false for apk the WebView would be invisible? then, I don't think the developer would set webview debugging to true every version just for testing.... – Kent Oct 13 '16 at 04:54
  • @Kent One thing you should k know is, You can not switch to WEBVIEW directly if there is no WEBVIEW present (It will throw an error). First get the list of available views using below code and switch to WEBVIEW. If you are not getting WEBVIEW in the the available contexts then that screen does not have WEBVIEW or developer has not enabled the remote debugging for WebView. However, As you are saying that your able to see WEBVIEW using chrome inspector tool then debugging is enabled for sure. – Vinod Oct 14 '16 at 04:33
  • @kent if u need to use webview for automation then debugging has to be enabled , there is no other workaround – krishna chetan Oct 14 '16 at 11:47

4 Answers4

0

Try the below code for switching to webView :

Set<String> contextNames = driver.getContextHandles();
    for(String context : contextNames) {
        if(context.toLowerCase().contains("web")){
            System.out.println("Context Name is " + context);
            driver.context(context);
            status=true;
            break;
        }
    }       
Vinod
  • 956
  • 7
  • 15
0

You have not mentioned if you have configured chromedriver in your desired capabilities. The driver will not identify WV until you have it set up within your tests.

Sabarish
  • 174
  • 4
  • 15
0

Try running webkit proxy it may help you

Run in Terminal:

ios_webkit_debug_proxy -c deviceID:27753 -d

to get deviceID:

instruments -s devices
Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
0

Looking at the docs, you need to enable webView debugging:

There is an additional step necessary within your app build, unfortunately. As described in the Android remote debugging docs it is necessary to set to true the setWebContentsDebuggingEnabled property on the android.webkit.WebView element.

Source: http://appium.io/docs/en/writing-running-appium/web/hybrid/

Also this response gives you some potentially useful code.

Stefan
  • 747
  • 8
  • 11