同有问题,好像是 WDA 已经支持,但是 Appium 还不支持
我的解决方案(仅供参考):
appium-xcuitest-driver@2.4.0
中的/lib/webdriveragent.js
的waitForStart
函数中,需要获得 WDA 的启动时间与系统时间做对比,导致reachedEnd
一直是false
,测试进程卡住,等待 WDA 启动,具体的代码如下:
async waitForStart (startTime) {
// we have to wait for the sim to start before we can tail the log file
if (!this.realDevice) {
await systemLogExists(this.device);
}
let agentUrl;
let lineCount = 0;
let reachedEnd = !this.realDevice; // simulator does not need to wait, since we are tailing
let showWaitingMessage = true; // turn off logging once we have hit the end
let startDetector = (stdout) => {
// on a real device there may already be system logs that need to be
// passed before we get to the real startup logs, otherwise
// we expect two lines, one after another
// Jul 20 13:03:57 iamPhone XCTRunner[296] <Warning>: Built at Jul 20 2016 13:03:50
// Jul 20 13:03:57 iamPhone XCTRunner[296] <Warning>: ServerURLHere->http://10.35.4.122:8100<-ServerURLHere
if (!reachedEnd) {
let dateMatch = REAL_DEVICE_BUILD_LOG_STARTTIME_REGEX.exec(stdout);
if (dateMatch) {
let buildTime = new Date(dateMatch[1]);
if (buildTime.isAfter(startTime)) {
reachedEnd = true;
}
}
}
if (reachedEnd) {
let match = AGENT_STARTED_REGEX.exec(stdout);
if (match) {
agentUrl = match[1];
log.info(`Detected that WebDriverAgent is running at url '${agentUrl}'`);
if (!agentUrl) {
log.errorAndThrow(new Error('No url detected from WebDriverAgent'));
}
showWaitingMessage = false;
return true;
}
}
// periodically log, so it does not look like everything died
lineCount++;
let threshold = this.realDevice ? 5000 : 200;
if (showWaitingMessage && lineCount % threshold === 0) {
log.debug('Waiting for WebDriverAgent server to finish loading...');
}
return false;
};
log.info('Waiting for WebDriverAgent to start on device');
await this.deviceLogs.start(startDetector);
log.info(`WebDriverAgent started at url '${agentUrl}'`);
return agentUrl;
}
解决方法:
当前的解决方案是修改对应代码:
if (!reachedEnd) {
// let dateMatch = REAL_DEVICE_BUILD_LOG_STARTTIME_REGEX.exec(stdout);
// if (dateMatch) {
// let buildTime = new Date(dateMatch[1]);
// if (buildTime.isAfter(startTime)) {
// reachedEnd = true;
// }
// }
reachedEnd = true;
log.info("ReachedEnd is set true!")
}
PS:
appium-xcuitest-driver@2.4.3
与 2.4.0 的源码不一样,但是原理差不多。
另外,需要修改 build 中编译后的文件或者修改后编译一下。