在测试 macaca 的并发,思路是开启两个线程。然后给每个线程上的任务分别设置不同的 udid 和端口号。
然后看是否能并发执行。
先用命令行开启两个 macaca server
1. macaca server -p 3456 --verbose
2. macaca server -p 3457 --verbose
端口 3457 对应 iPhone 7 Plus
端口 3456 对应 iPhone 6s
java 测试代码如下
import com.alibaba.fastjson.JSONObject;
/**
* Created by sixleaves on 2017/2/16.
*/
public class MClient implements Runnable{
private String port;
private String udid;
private macaca.client.MacacaClient driver = new macaca.client.MacacaClient();
public void run() {
JSONObject porps = new JSONObject();
porps.put("platformName", "ios");
porps.put("reuse", 1);
porps.put("udid", getUdid());
porps.put("platformVersion", "10.1.1");
porps.put("deviceName", "iPhone 7 plus");
porps.put("bundleId", "com.netdragon.quicktest");
porps.put("host", "127.0.0.1");
porps.put("port", getPort());
JSONObject desiredCapabilities = new JSONObject();
desiredCapabilities.put("desiredCapabilities", porps);
try {
driver.initDriver(desiredCapabilities);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
}
public class Main {
public static void main(final String[] args) {
String[] udids ={"1de34bc9fca390771d274bd72cd61ec85c750f02",
"55c36c2ae2c7da2091d4b07ef275a7a80cb31167"};
String[] ports = {"3456", "3457"};
for (int i = 0; i < 2; i++) {
MClient client = new MClient();
client.setPort(ports[i]);
client.setUdid(udids[i]);
new Thread(client).start();
}
}
}
运行后,能在 iPhone 6s 编译成功并启动对应程序,但是对于 iPhone 7Plus 只看到驱动编译到手机上,但是没法启动应用程序。并且 iPhone 7Plus 对应的服务端并没输出,而是输出到了 6s 那台服务器上。注意到日志的一个细节Proxy: /session:POST to http://127.0.0.1:8900/
., 两次的 POST 请求对应的端口号都一样? 这边是不是有问题,怎么解决?