Macaca driver.contexts () 与 driver.context (...) 调用时总是出现异常

sruru · March 22, 2017 · Last by Yinxl replied at March 29, 2017 · 1337 hits

请教下各位,我在开发macaca用例的时候,环境如下

总是得到如下错误,测试无法完成并终止测试

我的测试代码是:

Element ele = ...
ele.click();
if (ele == null || !ele.isDisplayed()) {
Assert.fail("button找不到");
}

driver.sleep(10000);

JSONArray contexts = driver.contexts();
System.out.println(contexts.getString(0));
System.out.println(contexts.getString(1));
System.out.println(contexts.getString(2));
driver.context(contexts.getString(1));
共收到 6 条回复 时间 点赞
sruru #1 · March 22, 2017 作者

@xdf @junhe 求助求助,非常感谢了,我已经google了一轮,也看了appium类似的错误,但是没有解决

sruru #2 · March 22, 2017 作者

我也测试过你们提供的macacatestsample工程,同样不通过,log是

>> chromedriver starting success.
>> proxy.js:52:14 [master] pid:24637 Proxy: /status:GET to http://localhost:9515/wd/hub/status:GET with body:
>> proxy.js:58:16 [master] pid:24637 Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Mac OS X\",\"version\":\"10.11.6\"}}}"
>> proxy.js:52:14 [master] pid:24637 Proxy: /session:POST to http://localhost:9515/wd/hub/session:POST with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.github.android_app_bootstrap","androidUseRunningApp":true,"androidDeviceSerial":"P4M7N15411033070"}}}
>> proxy.js:58:16 [master] pid:24637 Got response with status 200: {"sessionId":"2ef58ea8864a96aab301989f223c5513","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSel...
>> chromedriver ready with: {"
sessionId":null,"status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"platform":"ANDROID","rotatable":false,"takesHeapSnapshot":true,"takesScreenshot":true,"version":"30.0.0.0","webStorageEnabled":true}}
>> proxy.js:52:14 [master] pid:24637 Proxy: /wd/hub/session/temp/window_handles:GET to http://localhost:9515/wd/hub/session/2ef58ea8864a96aab301989f223c5513/window_handles:GET with body: {}
>> proxy.js:58:16 [master] pid:24637 Got response with status 200: {"
sessionId":"2ef58ea8864a96aab301989f223c5513","status":0,"value":["CDwindow-7721FCD5-9322-974B-D3BB-EA0F6CE0D087"]}
>> responseHandler.js:47:14 [master] pid:24637 Send HTTP Respone to Client: {"
sessionId":"70212602-a312-47aa-92ea-9b61ddfbb530","status":0,"value":"[\"NATIVE_APP\",\"CDwindow-7721FCD5-9322-974B-D3BB-EA0F6CE0D087\"]"}
>> responseHandler.js:11:12 [master] pid:24637 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/70212602-a312-47aa-92ea-9b61ddfbb530/context, jsonBody: {"name":"CDwindow-7721FCD5-9322-974B-D3BB-EA0F6CE0D087"}
>> proxy.js:52:14 [master] pid:24637 Proxy: /wd/hub/session/temp/window_handles:GET to http://localhost:9515/wd/hub/session/2ef58ea8864a96aab301989f223c5513/window_handles:GET with body: {}
>> proxy.js:58:16 [master] pid:24637 Got response with status 200: {"sessionId":"2ef58ea8864a96aab301989f223c5513","status":0,"value":["CDwindow-7721FCD5-9322-974B-D3BB-EA0F6CE0D087"]}
>> proxy.js:52:14 [master] pid:24637 Proxy: /wd/hub/session/temp/window:POST to http://localhost:9515/wd/hub/session/2ef58ea8864a96aab301989f223c5513/window:POST with body: {"name":"CDwindow-7721FCD5-9322-974B-D3BB-EA0F6CE0D087"}
>> proxy.js:58:16 [master] pid:24637 Got response with status 200: {"sessionId":"2ef58ea8864a96aab301989f223c5513","status":0,"value":null}
>> responseHandler.js:47:14 [master] pid:24637 Send HTTP Respone to Client: {"sessionId":"70212602-a312-47aa-92ea-9b61ddfbb530","status":0,"value":null}
>> responseHandler.js:11:12 [master] pid:24637 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/70212602-a312-47aa-92ea-9b61ddfbb530/element, jsonBody: {"using":"id","value":"pushView"}
>> proxy.js:52:14 [master] pid:24637 Proxy: /wd/hub/session/70212602-a312-47aa-92ea-9b61ddfbb530/element:POST to http://localhost:9515/wd/hub/session/2ef58ea8864a96aab301989f223c5513/element:POST with body: {"using":"id","value":"pushView"}
>> proxy.js:58:16 [master] pid:24637 Got response with status 200: {"sessionId":"2ef58ea8864a96aab301989f223c5513","status":0,"value":{"ELEMENT":"0.6726351859979331-1"}}
>> session.js:108:14 [master] pid:24637 Send HTTP Respone to Client: {"sessionId":"70212602-a312-47aa-92ea-9b61ddfbb530","status":0,"value":"{\"ELEMENT\":\"0.6726351859979331-1\"}"}
>> responseHandler.js:11:12 [master] pid:24637 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/70212602-a312-47aa-92ea-9b61ddfbb530/touch/click, jsonBody: {"element":"0.6726351859979331-1"}
>> responseHandler.js:23:14 [master] pid:24637 Send HTTP Respone to Client: 404 Not Found
>> responseHandler.js:11:12 [master] pid:24637 Recieve HTTP Request from Client: method: DELETE url: /wd/hub/session/70212602-a312-47aa-92ea-9b61ddfbb530, jsonBody: {}
>> session.js:81:12 [master] pid:24637 Delete session, sessionId: 70212602-a312-47aa-92ea-9b61ddfbb530
>> responseHandler.js:47:14 [master] pid:24637 Send HTTP Respone to Client: {"sessionId":"70212602-a312-47aa-92ea-9b61ddfbb530","status":0}
>> macaca-chromedriver.js:123:18 [master] pid:24637 chromedriver exit with code: null, signal: SIGTERM

这样试下:

JSONArray contexts = driver.contexts();
driver.context(contexts.get(0).toString());

sruru #4 · March 22, 2017 作者
Yinxl 回复

改了之后也没有效果,console的log是:

Response content:{"sessionId":"c4a27253-9a40-40d9-9479-bdc800668cea","status":6,"value":{"message":"no such session\n  (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)"}}
sruru 回复

嗯 也有可能是你的chromeDriver的版本和你的webview版本不一致

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up