Appium 求助:content 切换上下文模式,报错:(Original error: Did not get session redirect from Chromedriver)

匿名 · 2014年09月02日 · 最后由 海角 回复于 2015年08月23日 · 1562 次阅读

环境:
Appium:1.2.0.1
设备 Android 版本: 4.4.2
设备 SDK 版本: 19

Set<String> contextNames = appDriver.getContextHandles();
for (String contextName : contextNames) {
     System.out.println(contextName+"\n");
}

打印的结果:

NATIVE_APP

WEBVIEW_com.android.browser

而接下来执行下面这句时报错了:

appDriver.context("WEBVIEW_com.android.browser");

报错如下:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (Original error: Did not get session redirect from Chromedriver) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.75 seconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'jli', ip: '192.168.200.94', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: f0b6fa51-296f-477d-9b96-09e391ca4484
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{platform=LINUX, javascriptEnabled=true, appActivity=cn.mailtech.app.activity.SplashMailtech, browserName=, desired={newCommandTimeout=600, platformVersion=4.4, deviceName=NX507J, platformName=Android, browserName=, appActivity=cn.mailtech.app.activity.SplashMailtech, appPackage=cn.mailtech.app}, appPackage=cn.mailtech.app, newCommandTimeout=600, platformVersion=4.4, databaseEnabled=false, deviceName=NX507J, platformName=Android, webStorageEnabled=false, warnings={}, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
    at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:567)
    at com.mailtech.selenium2.example.appium.cmappTest.ReadMail2.ReadMailtest(ReadMail2.java:113)
    at com.mailtech.selenium2.example.appium.cmappTest.ReadMail2.ReadMailTest(ReadMail2.java:305)
    at com.mailtech.selenium2.example.appium.cmappTest.ReadMail2.testReadMail(ReadMail2.java:314)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Appium 的日志如下:
有 error: Chromedriver create session did not work.

> debug: Appium request initiated at /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484/contexts
> info: --> GET /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484/contexts {}
> debug: Request received with params: {}
> debug: Getting a list of available webviews
> debug: executing: "D:\adt-bundle-windows-x86_64-20140321\sdk\platform-tools\adb.exe" -s NX507J shell "cat /proc/net/unix"
> debug: WEBVIEW_32633 mapped to pid 32633
> debug: Getting process name for webview
> debug: executing: "D:\adt-bundle-windows-x86_64-20140321\sdk\platform-tools\adb.exe" -s NX507J shell "ps"
> debug: Parsed pid: 32633 pkg: com.android.browser
> info: <-- GET /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484/contexts 200 338.540 ms - 116 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.android.browser"],"sessionId":"f0b6fa51-296f-477d-9b96-09e391ca4484"}
> debug: from: u0_a17,32633,227,966956,65272,ffffffff,00000000,S,com.android.browser
> debug: returning process name: com.android.browser
> debug: Available contexts: 
> debug: ["WEBVIEW_com.android.browser"]
> debug: Available contexts: NATIVE_APP,WEBVIEW_com.android.browser
> debug: Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.android.browser"],"sessionId":"f0b6fa51-296f-477d-9b96-09e391ca4484"}
> debug: Appium request initiated at /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484/context
> debug: Request received with params: {"name":"WEBVIEW_com.android.browser"}
> debug: Getting a list of available webviews
> debug: executing: "D:\adt-bundle-windows-x86_64-20140321\sdk\platform-tools\adb.exe" -s NX507J shell "cat /proc/net/unix"
> debug: WEBVIEW_32633 mapped to pid 32633
> debug: Getting process name for webview
> debug: executing: "D:\adt-bundle-windows-x86_64-20140321\sdk\platform-tools\adb.exe" -s NX507J shell "ps"
> debug: Parsed pid: 32633 pkg: com.android.browser
> debug: from: u0_a17,32633,227,966956,65272,ffffffff,00000000,S,com.android.browser
> debug: returning process name: com.android.browser
> debug: Available contexts: NATIVE_APP,WEBVIEW_com.android.browser
> debug: ["WEBVIEW_com.android.browser"]
> debug: Available contexts: NATIVE_APP,WEBVIEW_com.android.browser
> debug: Connecting to chrome-backed webview
> debug: Creating Chrome session
> debug: Ensuring Chromedriver exists
> debug: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %b))
> debug: No old chromedrivers seemed to exist
> debug: Spawning chromedriver with: D:\AppiumForWindows\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
> debug: [CHROMEDRIVER] Starting ChromeDriver (v2.9.248315) on port 9515
> debug: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"cn.mailtech.app","androidUseRunningApp":true,"androidDeviceSerial":"NX507J"}}}}
> error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"e0e91a1f48274488dba92953b66ba6b6","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)"}}
> info: <-- POST /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484/context 500 61738.692 ms - 280 
> debug: Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: Did not get session redirect from Chromedriver)","origValue":"Did not get session redirect from Chromedriver"},"sessionId":"f0b6fa51-296f-477d-9b96-09e391ca4484"}
> info: --> DELETE /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484 {}
> debug: Appium request initiated at /wd/hub/session/f0b6fa51-296f-477d-9b96-09e391ca4484
> info: Shutting down appium session

尝试:在 android 安装 chrome,但结果仍旧一样。

共收到 10 条回复 时间 点赞

手机上有 chrome 么?需要 google framework 吧。

你的 webview 类型是啥?

匿名 #3 · 2014年09月03日

#1 楼 @lihuazhang 有的。 手机上默认没有 chrome,我自己安装了一个。 但也是一样的结果。

#3 楼 @liqing380 错误的日志就是说你没有正确安装 chrome。 你可以看看 /proc/net/unix 里面的内容

#4 楼 @lihuazhang 我发现 driver.switch_to.context('WEBVIEW') 成功后,手机一直停到当前页面,下一步应该怎么去获取 webview 的内容呢? 是要 browser = webdriver.Chrome() 吗?

你好,这个问题解决了吗?可否分享下经验,多谢~~

我也遇到同样的问题,最后怎么解决的啊,多谢~~

求解决方法

@irisliu 我今天也遇到了这个问题,已解决。
Appium 模式:现公布解决方法,首先可能需要更新 chromedriver 到最新版本(或者使用 appium1.4.0 自带 2.15.322448),在模拟器或手机端安装 chrome,版本号大于 33 即可(我使用的是 43.0.2357.93),做好以上准备工作后在任务管理器中干掉 chromedriver 进程。
运行成功后的 Appium 关键日志如下:

> info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.**.**
> info: [debug] Connecting to chrome-backed webview
> info: Set chromedriver binary as: d:\Program Files\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
> info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
> info: Successfully cleaned up old chromedrivers
> info: Spawning chromedriver with: d:\Program Files\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
> info: [CHROMEDRIVER STDOUT] Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
> Only local connections are allowed.
> info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
> info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"6.1 SP1"}}}
> info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.**.**","androidUseRunningApp":true,"androidDeviceSerial":"192.168.180.101:5555"}}}
> info: Got response with status 200: {"sessionId":"281726e22ffb4337f02a6649aff41056","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"0319316c-5f0e-4b90-952b-689313a56cbf"}
> info: <-- POST /wd/hub/session/0319316c-5f0e-4b90-952b-689313a56cbf/context 200 6008.816 ms - 76 {"status":0,"value":null,"sessionId":"0319316c-5f0e-4b90-952b-689313a56cbf"}
> info: --> POST /wd/hub/session/0319316c-5f0e-4b90-952b-689313a56cbf/element {"using":"id","value":"username"}
> info: Proxying [POST /wd/hub/session/0319316c-5f0e-4b90-952b-689313a56cbf/element] to [POST http://127.0.0.1:9515/wd/hub/session/281726e22ffb4337f02a6649aff41056/element] with body: {"using":"id","value":"username"}
> info: Got response with status 200: 

这个问题解决了吗?可否分享解决方案及原因?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册