请教下各位,我在开发 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));
我也测试过你们提供的 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());
改了之后也没有效果,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)"}}