Appium抛出"镀铬无法到达"偶尔切换上下文时

时间:2015-12-19 23:43:23

标签: java android selenium appium selenium-chromedriver

我使用的是appium 1.4.16和智能手机与Android 6。

运行此代码:

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

要切换到webview上下文,

投掷"铬无法到达"错误。

很少有开关工作。

我用谷歌搜索但可以解决它。你知道什么常见的解决方案" chrome无法访问"

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 个答案:

答案 0 :(得分:0)

我可以通过在测试执行期间一直监视chromedriver来获得修复,chromedriver在从natiove_app切换回webview时变得没有响应。我在https://github.com/mi2pankaj/chromeDriverHandler开发了一小段代码,它解决了我的所有问题,只需将这个jar chromedriverHandler.jar添加到你的项目中并使用ChromedriverHandler.chromeDriverHandlerThread()。start();在你的@beforeclass / @beforetest和ChromedriverHandler.chromeDriverHandlerThread()。stop();在@afterclass / @aftertest中。