question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to switch to WebView context on Android O

See original GitHub issue

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"}}}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ashishyadav2020commented, May 11, 2018

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.

0reactions
lock[bot]commented, May 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't switch context to webview - Issues/Bugs - Appium Discuss
The post i wrote initially relates to switching from native view to webview.Most of the test is executed on a native app when...
Read more >
Appium Unable to Switch from NativeApp to WebView in C# ...
I have an android apk file, after launching the app, it shows the Webview of the website. I am unable to switch from...
Read more >
Debug app WebView automation issues | BrowserStack Docs
After switching to the WebView context, your app is unable to interact with the loaded elements; WebView pages of the app fail to...
Read more >
Appium: Switch to Native & Web-view context for Hybrid App
In this video, we are going to see how we can switch from Native context to Webview context to automate hybrid app in...
Read more >
Automating hybrid apps - Appium
To stop automating in the web view context and go back to automating the native portion of the app, simply call context again...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found