appium: Unable to switch to WebView context on Android O

The problem

I have created a brand new empty android project and only added a WebView loading Amazon.com. All the test does is switch to the WebView context. This test works fine on Android 7.0 but hangs on Android O with the error message “chrome not reachable”.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.6.5
  • Desktop OS/version used to run Appium: MacOS Sierra
  • Mobile platform/version under test: Android O beta 4
  • Real device or emulator/simulator: Pixel XL
  • Appium CLI or Appium.app|exe: appium -a 127.0.0.1 -p 4723 --session-override --default-capabilities ‘{“app”:“/Users/jbruckn/AndroidStudioProjects/SimpleWebview/app/build/outputs/apk/app-debug.apk”,“clearSystemFiles”:“true”}’ --log-timestamp

Details

The android app is a brand new android project with this onCreate method in the MainActivity:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WebView webview = new WebView(this);
        setContentView(webview);

        WebView.setWebContentsDebuggingEnabled(true);
        webview.setWebViewClient(new WebViewClient());
        webview.setEnabled(true);
        webview.loadUrl("http://www.amazon.com");
    }

The test to switch to webview context:


public class SimpleTest {

    protected AndroidDriver driver;

    protected void prepareAndroidForAppium() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("device", "Android");
        capabilities.setCapability("deviceName", "HT7150200171");
        //capabilities.setCapability("deviceName", "00eb9785375094e6");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.example.jbruckn.simplewebview");
        capabilities.setCapability("appActivity", "com.example.jbruckn.simplewebview.MainActivity");
        capabilities.setCapability("autoWebview", "true");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @Test
    public void test() throws MalformedURLException, InterruptedException {
        prepareAndroidForAppium();

        driver.context(driver.getContextHandles().toArray()[1].toString());
    }

}

Link to Appium logs

https://gist.github.com/jbruckne/3087a38fbb9a1e95c54ace809222c0a0

Each time the following request is made for the context switch, it hangs for about half a minute.

[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.example.jbruckn.simplewebview","androidUseRunningApp":true,"androidDeviceSerial":"HT7150200171"}}}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 59 (18 by maintainers)

Most upvoted comments

Hi guys, I came across one rebuild of chromedriver and using this with Android version 7 solve my problem with WEBVIEWs.

You can download and give a quick try https://github.com/ITKarel/ChromeDriver.