Appium throws “chrome not reachable” sporadically when switch a context

十年热恋 提交于 2019-12-13 07:05:01

问题


I'm using appium 1.4.16 and smartphone with Android 6.

Running this code:

    public boolean fluentWaitChangeContext(String context, int timeout) {
        Wait wait = new FluentWait(driver)
                .withTimeout(timeout, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class, NoSuchContextException.class);

        boolean isFound = false;
        try {
            wait.until(input -> {
                if (driver.getContextHandles().size() == 2) {
                    driver.context(context);
//                    driver.context(driver.getContextHandles().toArray()[1].toString());
                    return true;
                }
                return null;
            });
        } catch (org.openqa.selenium.TimeoutException exc) {

        }
        return isFound;
    }

To switch to a webview context,

Throws "chrome not reachable" error.

Rarely the switch works.

I googled but could fix it. What common solution do you know for "chrome not reachable"

info: [debug] returning process name: com.ridewith
    info: [debug] Available contexts: NATIVE_APP,WEBVIEW_undefined
    info: [debug] ["WEBVIEW_com.ridewith"]
    info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
    info: [debug] Connecting to chrome-backed webview
    info: Chromedriver: Changed state to 'starting'
    info: Chromedriver: Set chromedriver binary as: /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
    info: Chromedriver: Killing any old chromedrivers, running: ps -ef | grep /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver | grep -v grep |grep -e '--port=9515\(\s.*\)\?$' | awk '{ print $2 }' | xargs kill -15
    info: Chromedriver: Successfully cleaned up old chromedrivers
    info: Chromedriver: Spawning chromedriver with: /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=9515
    info: Chromedriver: [STDOUT] Starting ChromeDriver 2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281) on port 9515
    Only local connections are allowed.
    info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
    info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Mac OS X\",\"version\":\"10.11.2\"}}}"
    info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
    info: JSONWP Proxy: Got response with status 200: {"sessionId":"4d6fe365883b68ea3847ea62c78d6de3","status":13,"value":{"message":"unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19...
    info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
    info: JSONWP Proxy: Got response with status 200: {"sessionId":"ac2dfd0e9d586348bdb247433286590e","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=M...
    info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
    info: [debug] [BOOTSTRAP] [debug] Emitting system alert message
    info: [debug] Emitting alert message...
    info: JSONWP Proxy: Got response with status 200: {"sessionId":"974a95bde40483689bb537c23d0a0a8d","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=M...
    info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
    info: JSONWP Proxy: Got response with status 200: {"sessionId":"5a5f42437c86db7056dbfbb28c532a77","status":13,"value":{"message":"unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19...
    error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM

回答1:


I could get a fix by monitoring chromedriver all the time during test execution, chromedriver becomes unresponsive while switching back to webview from natiove_app. I developed a small piece of code available at https://github.com/mi2pankaj/chromeDriverHandler, it has solved my all problems, just add this jar chromedriverHandler.jar to your project and use ChromedriverHandler.chromeDriverHandlerThread().start(); in your @beforeclass / @beforetest and ChromedriverHandler.chromeDriverHandlerThread().stop(); in your @afterclass / @aftertest.



来源:https://stackoverflow.com/questions/34376582/appium-throws-chrome-not-reachable-sporadically-when-switch-a-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!