macaca icon indicating copy to clipboard operation
macaca copied to clipboard

macaca java 脚本中第一个 byname 可以执行成功,第二个就提示失败

Open zhqjsj opened this issue 7 years ago • 6 comments

macaca doctor



More information: https://macacajs.github.io/changelog.html

macaca-doctor version: 2.0.15

Node.js checklist:

node env: /usr/local/bin/node node version: v8.12.0

iOS checklist:

Xcode Command Line Tools is ready, version: 2349. xcodebuild version: 9.4 iproxy[usbmuxd] is installed at: /usr/local/bin/iproxy ios_webkit_debug_proxy is installed at: /usr/local/bin/ios_webkit_debug_proxy

Android checklist:

JAVA version is 1.8 JAVA_HOME is set to /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home ANDROID_HOME is set to /Users/dlxx/Library/Android/android-sdk-macosx Platforms is set to /Users/dlxx/Library/Android/android-sdk-macosx/platforms/android-26 ADB tool is set to /Users/dlxx/Library/Android/android-sdk-macosx/platform-tools/adb gradle is installed, version: 4.7

Installed driver list:

android: 2.0.46 [out-of-date] ios: 2.0.34 [out-of-date]

  • Macaca Doctor Logs:

  • Operate System: mac os 10.13.6 xcode 9.4

  • Programming Language: java

同样的macaca-cli版本,macaca-android版本,在windows电脑上是可以正常运行的,在mac电脑上运行失败 使用mac电脑测试android,macaca-java测试脚本中包含以下内容 : driver.elementByName("我的").click(); driver.sleep(3000);

driver.elementByName("关于").click(); Thread.sleep(3000);

driver.elementByName("功能介绍").click(); Thread.sleep(3000);

脚本: package macaca.client;

import java.io.File; import java.io.IOException;

import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test;

import com.alibaba.fastjson.JSONObject;

public class NewTest { MacacaClient driver = new MacacaClient();

String port;
String udid;
String proxyport;


public NewTest() throws IOException {
}

@Parameters({ "port", "udid", "proxyport" }) ///// -------从testng文件读取值
@BeforeTest
public void beforeSuite(String port, String udid, String proxyport) {
	this.port = port;
	this.udid = udid;
	this.proxyport = proxyport;
}

@BeforeClass
public void setUp() throws Exception {
	// platform: android or ios
	String platform = "android";

	JSONObject porps = new JSONObject();
	porps.put("platformName", platform);
	porps.put("app", "/Users/dlxx/Desktop/android/XXXX.zip");
	porps.put("reuse", 3);
	// porps.put("activity", ".BootUI"); // appActivity
	porps.put("udid", udid);
	// porps.put("proxyPort", Integer.parseInt(proxyport));
	JSONObject desiredCapabilities = new JSONObject();
	// desiredCapabilities.put("host", "localhost"); // custom server host
	desiredCapabilities.put("port", Integer.parseInt(port)); // custom
																// server
																// port
	desiredCapabilities.put("desiredCapabilities", porps);
	// driver.initDriver(desiredCapabilities);
	try {
		driver.initDriver(desiredCapabilities);
	} catch (Exception e) {
		e.printStackTrace();
	}
}

@Test
public void testCaseOne() throws Exception {

	System.out.println("------------test-------------------");
	Thread.sleep(3000);

	driver.elementByName("我的").click();
	Thread.sleep(3000);

	driver.elementByName("关于").click();
	Thread.sleep(3000);

	driver.elementByName("功能介绍").click();
	Thread.sleep(3000);
}

@AfterClass
public void tearDown() throws Exception {
	driver.quit();
}

}

现在每次执行都在driver.elementByName("关于").click();语句时执行失败,eclipse日志: 2018-10-15 14:24:44 Request:http://localhost:3456/wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element:using":"name","value":"我的"}{" 2018-10-15 14:24:47 Response:{"status":0,"value":{"ELEMENT":"1"},"sessionId":null} 2018-10-15 14:24:47 Request:http://localhost:3456/wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element/1/click:{} 2018-10-15 14:24:49 Response:{"status":0,"sessionId":"bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e"} 2018-10-15 14:24:52 Request:http://localhost:3456/wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element:using":"name","value":"关于"}{" 2018-10-15 14:24:52 Response:BAD REQUEST: Syntax error. HTTP verb {}POST unhandled. 2018-10-15 14:24:52 Response:{"sessionId":"bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e","status":0}

macaca server日志:

    UIAutomatorWD http server ready
    macaca-android.js:303:10 [master] pid:2936 start app with: {"package":"com.dlxx.mam.gw","activity":""}
    responseHandler.js:49:14 [master] pid:2936 Send HTTP Respone to Client[2018-10-15 14:24:41]: {"sessionId":"bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e","status":0,"value":"{\"app\":\"/var/folders/fb/vqg8m_xd13902672dtrvw1jh0000gn/T/Robot-2.60.60-2018-10-12-15-21.apk\",\"proxyPort\":8910,\"reuse\":3,\"platformName\":\"android\",\"udid\":\"9963d01d\"}"}
    responseHandler.js:11:12 [master] pid:2936 Recieve HTTP Request from Client[2018-10-15 14:24:44]: method: POST url: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element, jsonBody: {"using":"name","value":"我的"}
    proxy.js:56:14 [master] pid:2936 Proxy: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element:POST to http://127.0.0.1:9002/wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element:POST with body: {"using":"name","value":"我的"}
    proxy.js:86:20 [master] pid:2936 Got response with status 200: {"status":0,"value":{"ELEMENT":"1"},"sessionId":null}
    session.js:120:14 [master] pid:2936 Send HTTP Respone to Client[2018-10-15 14:24:47]: {"status":0,"value":"{\"ELEMENT\":\"1\"}","sessionId":null}
    responseHandler.js:11:12 [master] pid:2936 Recieve HTTP Request from Client[2018-10-15 14:24:47]: method: POST url: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element/1/click, jsonBody: {}
    proxy.js:56:14 [master] pid:2936 Proxy: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element/1/click:POST to http://127.0.0.1:9002/wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element/1/click:POST with body: {}
    proxy.js:86:20 [master] pid:2936 Got response with status 200: {"status":0,"sessionId":"bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e"}
    session.js:120:14 [master] pid:2936 Send HTTP Respone to Client[2018-10-15 14:24:49]: {"status":0,"sessionId":"bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e"}
    responseHandler.js:11:12 [master] pid:2936 Recieve HTTP Request from Client[2018-10-15 14:24:52]: method: POST url: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element, jsonBody: {"using":"name","value":"关于"}
    proxy.js:56:14 [master] pid:2936 Proxy: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element:POST to http://127.0.0.1:9002/wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e/element:POST with body: {"using":"name","value":"关于"}
    proxy.js:77:24 [master] pid:2936 Fail to parse body: SyntaxError: Unexpected token B in JSON at position 0
    proxy.js:86:20 [master] pid:2936 Got response with status 400: "BAD REQUEST: Syntax error. HTTP verb {}POST unhandled."
    session.js:120:14 [master] pid:2936 Send HTTP Respone to Client[2018-10-15 14:24:52]: "BAD REQUEST: Syntax error. HTTP verb {}POST unhandled."
    responseHandler.js:11:12 [master] pid:2936 Recieve HTTP Request from Client[2018-10-15 14:24:52]: method: DELETE url: /wd/hub/session/bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e, jsonBody: {}
    session.js:91:12 [master] pid:2936 Delete session, sessionId: bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e
    responseHandler.js:49:14 [master] pid:2936 Send HTTP Respone to Client[2018-10-15 14:24:52]: {"sessionId":"bbb5ebd6-ad33-4e17-a708-f2d0c9dd2e6e","status":0}

zhqjsj avatar Oct 17 '18 14:10 zhqjsj

看日志没有看出问题,辛苦在 driver.elementByName("我的").click(); 后面加两行: driver.sleep(3000); driver.source(); 打印一下当前视图的source-tree,确认视图树已经更新为新页面的

Yinxl avatar Oct 23 '18 08:10 Yinxl

This is the translated issue comment: @Yinxl


Look at the log without seeing the problem, hard work driver.elementByName("my").click(); Add two lines at the back: Driver.sleep(3000); Driver.source(); Print the source-tree of the current view to confirm that the view tree has been updated to the new page.

macaca-bot avatar Oct 23 '18 08:10 macaca-bot

This is the translated issue comment: @zhqjsj


responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:22]: method: POST url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/element, jsonBody: {"using":"name","value":"About"} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element:POST to http://127.0.0.1:9002/wd/ Hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element:POST with body: {"using":"name","value":"About"} proxy.js:86:20 [master] pid:1710 Got response with status 200: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"c17594fd-c4a5 -4422-ad2e-23621d27e71e"} session.js:120:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:24]: {"status":0,"value":"{"ELEMENT\ ":"1"}","sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e"} responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:24]: method: POST url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/element/1/click, jsonBody: {} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element/1/click:POST to http://127.0.0.1: 9002/wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element/1/click:POST with body: {} proxy.js:86:20 [master] pid:1710 Got response with status 200: {"status":0,"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e"} session.js:120:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:24]: {"status":0,"sessionId":"c17594fd-c4a5-4422 -ad2e-23621d27e71e"} responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: GET url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/source, jsonBody: {} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/:sessionId/source:GET to http://127.0.0.1:9002/wd/hub/session/c17594fd-c4a5 -4422-ad2e-23621d27e71e/source:GET with body: null proxy.js:77:24 [master] pid:1710 Fail to parse body: SyntaxError: Unexpected token B in JSON at position 0 proxy.js:86:20 [master] pid:1710 Got response with status 400: "BAD REQUEST: Syntax error. HTTP verb {}GET unhandled." responseHandler.js:56:12 [master] pid:1710 Send Error Respone to Client: TypeError: Cannot read property 'hierarchy' of undefined responseHandler.js:62:14 [master] pid:1710 TypeError: Cannot read property 'hierarchy' of undefined     At Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40)     At controllers.getSource.next ()     At onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19)     At     At process._tickCallback (internal/process/next_tick.js:189:7)

  TypeError: Cannot read property 'hierarchy' of undefined       At Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40)       At controllers.getSource.next ()       At onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19)       At       At process._tickCallback (internal/process/next_tick.js:189:7)

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: DELETE url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e, jsonBody: {} session.js:91:12 [master] pid:1710 Delete session, sessionId: c17594fd-c4a5-4422-ad2e-23621d27e71e responseHandler.js:49:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:27]: {"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e", "status": 0}

macaca-bot avatar Jan 07 '19 01:01 macaca-bot

This is the translated issue comment: @zhqjsj


After adding driver.source, the execution of the statement on the following failed, the log is as follows:

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:22]: method: POST url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/element, jsonBody: {"using":"name","value":"About"} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element:POST to http://127.0.0.1:9002/wd/ Hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element:POST with body: {"using":"name","value":"About"} proxy.js:86:20 [master] pid:1710 Got response with status 200: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"c17594fd-c4a5 -4422-ad2e-23621d27e71e"} session.js:120:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:24]: {"status":0,"value":"{"ELEMENT\ ":"1"}","sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e"} responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:24]: method: POST url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/element/1/click, jsonBody: {} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element/1/click:POST to http://127.0.0.1: 9002/wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/element/1/click:POST with body: {} proxy.js:86:20 [master] pid:1710 Got response with status 200: {"status":0,"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e"} session.js:120:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:24]: {"status":0,"sessionId":"c17594fd-c4a5-4422 -ad2e-23621d27e71e"} responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: GET url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/source, jsonBody: {} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/:sessionId/source:GET to http://127.0.0.1:9002/wd/hub/session/c17594fd-c4a5 -4422-ad2e-23621d27e71e/source:GET with body: null proxy.js:77:24 [master] pid:1710 Fail to parse body: SyntaxError: Unexpected token B in JSON at position 0 proxy.js:86:20 [master] pid:1710 Got response with status 400: "BAD REQUEST: Syntax error. HTTP verb {}GET unhandled." responseHandler.js:56:12 [master] pid:1710 Send Error Respone to Client: TypeError: Cannot read property 'hierarchy' of undefined responseHandler.js:62:14 [master] pid:1710 TypeError: Cannot read property 'hierarchy' of undefined     At Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40)     At controllers.getSource.next ()     At onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19)     At     At process._tickCallback (internal/process/next_tick.js:189:7)

  TypeError: Cannot read property 'hierarchy' of undefined       At Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40)       At controllers.getSource.next ()       At onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19)       At       At process._tickCallback (internal/process/next_tick.js:189:7)

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: DELETE url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e, jsonBody: {} session.js:91:12 [master] pid:1710 Delete session, sessionId: c17594fd-c4a5-4422-ad2e-23621d27e71e responseHandler.js:49:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:27]: {"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e", "status": 0}

macaca-bot avatar Jan 07 '19 01:01 macaca-bot

增加了driver.source后,执行关于后的语句失败,日志如下: session.js:120:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:24]: {"status":0,"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e"}

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: GET url: /wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/source, jsonBody: {} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/:sessionId/source:GET to http://127.0.0.1:9002/wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e/source:GET with body: null proxy.js:77:24 [master] pid:1710 Fail to parse body: SyntaxError: Unexpected token B in JSON at position 0 proxy.js:86:20 [master] pid:1710 Got response with status 400: "BAD REQUEST: Syntax error. HTTP verb {}GET unhandled." responseHandler.js:56:12 [master] pid:1710 Send Error Respone to Client: TypeError: Cannot read property 'hierarchy' of undefined responseHandler.js:62:14 [master] pid:1710 TypeError: Cannot read property 'hierarchy' of undefined at Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40) at controllers.getSource.next () at onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19) at at process._tickCallback (internal/process/next_tick.js:189:7)

TypeError: Cannot read property 'hierarchy' of undefined at Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40) at controllers.getSource.next () at onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19) at at process._tickCallback (internal/process/next_tick.js:189:7)

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: DELETE url: /wd/hub/session/c17594fd-c4a5-4422-ad2e-23621d27e71e, jsonBody: {} session.js:91:12 [master] pid:1710 Delete session, sessionId: c17594fd-c4a5-4422-ad2e-23621d27e71e responseHandler.js:49:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:27]: {"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e","status":0}

zhqjsj avatar Jan 07 '19 01:01 zhqjsj

This is the translated issue comment: @zhqjsj


After the driver.source is added, the execution of the statement after the failure fails. The log is as follows: Session.js:120:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:24]: {"status":0,"sessionId":"c17594fd-c4a5-4422-ad2e -23621d27e71e"}

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: GET url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e/source, jsonBody: {} proxy.js:56:14 [master] pid:1710 Proxy: /wd/hub/session/:sessionId/source:GET to http://127.0.0.1:9002/wd/hub/session/c17594fd-c4a5 -4422-ad2e-23621d27e71e/source:GET with body: null proxy.js:77:24 [master] pid:1710 Fail to parse body: SyntaxError: Unexpected token B in JSON at position 0 proxy.js:86:20 [master] pid:1710 Got response with status 400: "BAD REQUEST: Syntax error. HTTP verb {}GET unhandled." responseHandler.js:56:12 [master] pid:1710 Send Error Respone to Client: TypeError: Cannot read property 'hierarchy' of undefined responseHandler.js:62:14 [master] pid:1710 TypeError: Cannot read property 'hierarchy' of undefined     At Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40)     At controllers.getSource.next ()     At onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19)     At     At process._tickCallback (internal/process/next_tick.js:189:7)

  TypeError: Cannot read property 'hierarchy' of undefined       At Android.controllers.getSource (/usr/local/lib/node_modules/macaca-android/lib/controllers.js:142:40)       At controllers.getSource.next ()       At onFulfilled (/usr/local/lib/node_modules/macaca-cli/node_modules/[email protected]@co/index.js:65:19)       At       At process._tickCallback (internal/process/next_tick.js:189:7)

responseHandler.js:11:12 [master] pid:1710 Recieve HTTP Request from Client[2019-01-07 09:04:27]: method: DELETE url: /wd/hub/session/c17594fd-c4a5-4422 -ad2e-23621d27e71e, jsonBody: {} session.js:91:12 [master] pid:1710 Delete session, sessionId: c17594fd-c4a5-4422-ad2e-23621d27e71e responseHandler.js:49:14 [master] pid:1710 Send HTTP Respone to Client[2019-01-07 09:04:27]: {"sessionId":"c17594fd-c4a5-4422-ad2e-23621d27e71e", "status": 0}

macaca-bot avatar Jan 07 '19 01:01 macaca-bot