Appium Appium1.6.3+iOS 10.2 一直 Waiting for WebDriverAgent server to finish loading...

zuiniao123 · 2016年12月18日 · 最后由 Kevin Tu 回复于 2019年09月19日 · 2375 次阅读

同样的配置在 Appium1.6.3+iOS 9.3 就能跑起来,在 Appium1.6.3+iOS 10.2 上 (已经添加了'XCUITest') 就一直处于 Waiting for WebDriverAgent server to finish loading...不动了

操作步骤:

1.wda 签名并且用 xcodebuild 命令装在手机上

2.命令行启动 appium

3.log 一直显示 Waiting for WebDriverAgent server to finish loading...不动了

有没有大神经历过的,求解救😳

Last login: Sun Dec 18 19:35:39 on ttys000
suqingdeMacBook-Pro:~ xcc$ appium
[Appium] Welcome to Appium v1.6.3
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/xcc/Desktop/应用名称.ipa","platformVersion":"10.2","bundleId":"com.应用名称.应用名称","automationName":"XCUITest","platformName":"iOS","udid":"7e7b54c63xxxxxxxxxxxx1aeb3dcf0ace1e7","deviceName":"iPhone 6"}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"/Users/xcc/Desktop/应用名称.ipa","platformVersion":"10.2","bundleId":"com.应用名称.应用名称","automationName":"XCUITest","platformName":"iOS","udid":"7e7b54c63xxxxxxxxxxxx1aeb3dcf0ace1e7","deviceName":"iPhone 6"},null,null,null,null]
[Appium] Creating new XCUITestDriver session
[Appium] Capabilities:
[Appium]   app: '/Users/xcc/Desktop/应用名称.ipa'
[Appium]   platformVersion: '10.2'
[Appium]   bundleId: 'com.应用名称.应用名称'
[Appium]   automationName: 'XCUITest'
[Appium]   platformName: 'iOS'
[Appium]   udid: '7e7b54c63xxxxxxxxxxxx1aeb3dcf0ace1e7'
[Appium]   deviceName: 'iPhone 6'
[debug] [XCUITest] XCUITestDriver version: 2.4.3
[BaseDriver] Session created with session id: a819d5cf-17f8-4143-9d98-4180c49c5fa9
[debug] [XCUITest] Xcode version set to '8.2'
[debug] [XCUITest] iOS SDK Version set to '10.2'
[debug] [XCUITest] Available devices: 7e7b54c63xxxxxxxxxxxx1aeb3dcf0ace1e7, c4b16cefccccccccccccb43a9b88819
[debug] [XCUITest] Creating iDevice object with udid 7e7b54c63xxxxxxxxxxxx1aeb3dcf0ace1e7
[XCUITest] Determining device to run tests on: udid: '7e7b54c63xxxxxxxxxxxx1aeb3dcf0ace1e7', real device: true
[BaseDriver] Using local app '/Users/xcc/Desktop/应用名称.ipa'
[debug] [BaseDriver] Copying local zip to tmp dir
[debug] [BaseDriver] Unzipping /var/folders/vn/c4srrmj53f367lw984kxs1100000gn/T/20161118-2308-5ymsl3.lobf0f6r/appium-app.zip
[debug] [BaseDriver] Testing zip archive: /var/folders/vn/c4srrmj53f367lw984kxs1100000gn/T/20161118-2308-5ymsl3.lobf0f6r/appium-app.zip
[BaseDriver] Unzipped local app to '/var/folders/vn/c4srrmj53f367lw984kxs1100000gn/T/20161118-2308-5ymsl3.lobf0f6r/Payload/应用名称.app'
[debug] [XCUITest] Checking whether app '/var/folders/vn/c4srrmj53f367lw984kxs1100000gn/T/20161118-2308-5ymsl3.lobf0f6r/Payload/应用名称.app' is actually present
[debug] [XCUITest] App is present
[debug] [iOSLog] Attempting iOS device log capture via libimobiledevice idevicesyslog
[debug] [iOSLog] Found idevicesyslog: '/usr/local/bin/idevicesyslog'
[XCUITest] Setting up real device
[debug] [XCUITest] App is already installed.
[debug] [XCUITest] Full reset not requested. No need to install.
[XCUITest] Using WDA path: '/usr/local/lib/node_modules/appium/node_modules/.2.4.3@appium-xcuitest-driver/WebDriverAgent'
[XCUITest] Using WDA agent: '/usr/local/lib/node_modules/appium/node_modules/.2.4.3@appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj'
[XCUITest] Launching WebDriverAgent on the device
[debug] [XCUITest] Carthage found: /usr/local/bin/carthage
[debug] [XCUITest] Killing hanging processes
[debug] [XCUITest] Using real device logger 'idevicesyslog'
[debug] [XCUITest] Beginning test with command 'xcodebuild build test -project /usr/local/lib/node_modules/appium/node_modules/.2.4.3@appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=7e7b54c632bcaa44f661726271aeb3dcf0ace1e7 -configuration Debug' in directory '/usr/local/lib/node_modules/appium/node_modules/.2.4.3@appium-xcuitest-driver/WebDriverAgent'
[XCUITest] Waiting for WebDriverAgent to start on device
[debug] [XCUITest] Log file for xcodebuild test: /Users/xcc/Library/Developer/Xcode/DerivedData/WebDriverAgent-cdbymtonqyssjhfwnanxtomfuiox/Logs/Test/E7B7B6B5-8059-4318-AD61-94CBF29F586F/Session-WebDriverAgentRunner-2016-12-18_193752-eXQWNA.log
[debug] [WebDriverAgent] Device: Dec 18 19:37:59 iPhone XCTRunner[472] <Notice>: Running tests...
[debug] [WebDriverAgent] Device: Dec 18 19:38:01 iPhone XCTRunner[472] <Notice>: Continuing to run tests in the background with task ID 1
[debug] [XCUITest] Waiting for WebDriverAgent server to finish loading...
[debug] [XCUITest] Waiting for WebDriverAgent server to finish loading...
[debug] [XCUITest] Waiting for WebDriverAgent server to finish loading...
[debug] [XCUITest] Waiting for WebDriverAgent server to finish loading...
[debug] [XCUITest] Waiting for WebDriverAgent server to finish loading...
共收到 29 条回复 时间 点赞
chen.zhou 回复

你解决了吗?遇到同样的问题

匿名 #31 · 2017年07月27日
chen.zhou 回复

我手机上 webdriverAgent 启动了,用 iproxy 8100 8100,后。 访问电脑http://xxxxx:8100/inspector,打不开,有知道为什么的吗?我搞不明白,希望知道的能解答下,谢谢
你解决了吗

匿名 #30 · 2017年07月27日

我手机上 webdriverAgent 启动了,用 iproxy 8100 8100,后。 访问电脑http://xxxxx:8100/inspector,打不开,有知道为什么的吗?我搞不明白,希望知道的能解答下,谢谢

meil000 回复

您好,我的是 IOS10.2 手机
(1)使用命令 “xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=你的 UDID' test” 一直卡在 Set Up:
Test Case '-[UITestingUITests testRunner]' started.
t = 0.00s Start Test at 2016-12-20 09:58:02:209
t = 0.01s Set Up
(2)命令 “iproxy 8100 8100” 输出:
recv failed: Resource temporarily unavailable
recv failed: Resource temporarily unavailable
recv failed: Resource temporarily unavailable
recv failed: Operation not permitted
(3)打开 “http://localhost:8100/status” 是好的,但是打开 “http://localhost:8100/inspector” 显示空白,请教下是怎么回事?
(4)打开手机上的 WebDriverAgent App 整个黑屏
请问大神有什么解决方法吗?看到前面的回复说可能是国行手机的问题,那现在这个问题有解决吗?

promise 回复

是的,这个国行 iphone 的问题,之前在 facebook 的 github 上已经有人确认了,只有国行有问题,你换港行就没有问题。
最近 Facebook 有没有解决这个 bug 我还不清楚。我一直用 iproxy 映射 USB 连接规避这个问题的。

陈琪 回复

这个 Listening on USB 的日志提示,我后来发现似乎不同版本 iphone 有的会打印,有的不打印,但不影响实际测试。
比如目前我的 iphone6P 启动 WDA 后,并不提示 Listening on USB,但 appium 运行自动化一切正常,所以个人觉得可以忽略了。

xcode8.2 没有 ios 10.2 的 sdk 吧,xcode 里看一下。记得应该是 xcode8.2.1 集成了 ios10.2 的 sdk

我昨天也遇到這樣的問題後來我找了一個方法
cd /usr/local/lib/node_modules/appium
npm uninstall appium-xcuitest-driver
npm install appium-xcuitest-driver@2.5.3
就可以嚕~ 可以試試看

meil000 回复

大神 请问一下,这个问题只存在于国行手机吗,如果我换了非国行的手机,是不是就不会一直 waiting 了

meil000 回复

Appium 还是超时。直接 localhost 直接 curl 那个接口很不稳定,经常没有返回。iproxy 的日志:
recv failed: Resource temporarily unavailable
recv failed: Resource temporarily unavailable
recv failed: Resource temporarily unavailable
recv failed: Resource temporarily unavailable
recv failed: Resource temporarily unavailable

国行真机真的有点儿扯。
稍后试试 WDA 自己的 USB 链接方式看看行不行。

@meil000 @zuiniao123 我也遇到这个问题了,你们清楚是什么引起的了嘛? 同一台手机,在公司电脑安装好的环境可以了,回到家里 mbp 安装环境后出现这个问题

steven iOS 真机运行 Appium 长期答疑! 中提及了此贴 03月04日 22:25
meil000 回复

你好 请问 Listening on USB 没有的那个问题解决了吗?10.2 的真机我这边也没有显示,但是虚拟机 10.2 的却有。

#16 楼 @meil000 这个方法挺赞的。解决了一个手机卡在 wda 启动时的问题

@ 楼主 请问解决了吗
该怎么解决这个问题 各位大神

17楼 已删除

一个月前遇到这个问题,也看到这个帖子可惜没有解决方法。。后来自己折腾了几天解决了,说一下我的解决方法吧,虽然不一定每个人的问题都相同,至少可以尝试一下:
appium 到目前为止,使用的 FB 提供的 webdriveragent 驱动一直存在一个 bug,不支持中国国行全系 iphone 的 wifi 连接,FB 也没有打算修复此 bug,如果大家用 appium 测试中国国行 iphone,webdriveragent 就可能一直卡死,解决方法是使用 iproxy 将 wifi 的 tcp 协议转换成 usb 协议,具体方法:
1)安装并启动 iproxy 把 webdriveragent 的默认 8100 端口转到 usb 协议(安装需联网):
$ brew uninstall ideviceinstaller
$ brew uninstall libimobiledevice
$ brew install --HEAD libimobiledevice
$ brew install ideviceinstaller
$ iproxy 8100 8100
注意 webdriveragent 监听的默认端口是 8100,如果你修改过端口,这里就改成你定义的端口
2)手动启动 webdriveragent:
xcodebuild -project /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id= 你的设备 UDID’ test
3)确认 webdriveragent 在 iphone 上安装并启动后,就可以启动 appium 了,重要的是在启动 appium 的 cap 中传入下面这个参数,让 appium 连接上面步骤中手动启动的 WebDriverAgent:

webDriverAgentUrl
http://localhost:8100

上面是关键!要传入这个 cap,不要让 appium 自己启动 WebDriverAgent,因为前面说了,appium 自己启动 WebDriverAgent 会引发 bug,导致中国国行手机无法与 WebDriverAgent 通过 tcp 协议通信,然后一直卡死。
4)执行测试用例,看看这次是不是不会卡着了。。。

Appium1.6.3, iOS10.1.1,楼上的各种方法都试过了,也还是一样的错误,没有 listen on USB 出来。 @shljsh 请问还有其他解决方法吗? 降级、升级、改 12 楼的代码 这些都试过了还是不行。

我也是遇到同样问题,有没有大神解决。另外我导出的 debug 版的 ipa 包装到模拟器上,一打开就闪退,不知道啥原因

我的解决方案(仅供参考):

appium-xcuitest-driver@2.4.0中的/lib/webdriveragent.jswaitForStart函数中,需要获得 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 中编译后的文件或者修改后编译一下。

现在 xcuitest 有 2.5.0 的版本了 试了下已经可以把真机的 app 拉起来了

#9 楼 @miaomiao413 我自己试过是好用的 2.4.2 的版本我也拉不起来 降级到 2.0.36 就没问题

@shljsh 按你的方法,APP 拉不起来

The problem solved by installing xcuitest-driver VERSION v2.0.36 (downgraded from v2.4.2)

cd /usr/local/lib/node_modules/appium
npm uninstall appium-xcuitest-driver
npm install appium-xcuitest-driver@2.0.36

我也遇到同样的问题啊,烦恼啊

appium1.6.3 支持 IOS 真机测试吗?

#4 楼 @zuiniao123 不好意思之前写错命令,是执行这个命令 “xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=你的 UDID' test”,你是在 xcode 里面运行 test 后看到提示 Listening on USB,还是在 Terminal 运行上面命令后看到提示 Listening on USB? 我的 iphone6P 是国行的,不知道和手机型号有没有关系。。

#3 楼 @meil000 。。。我后来又试了,在 ios10.2 上也有 Listening on USB 的提示的

#2 楼 @zuiniao123 我发现应该是 WebDriverAgent 的 BUG(Appium 就是调用 WebDriverAgent 实现 XUITest 真机自动化),我用 IOS9.3 和 IOS10.2 两部手机做了试验,用 Terminal 进入到 WebDriverAgent 工程目录下,连接手机后运行命令"xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=你的 UDID' test",可以看到区别:

1:IOS9.3 手机的运行结果明确提示:Listening on USB

2:IOS10.2 手机的运行结果没有上面的提示,而是一直卡在下面这段:
Test Case '-[UITestingUITests testRunner]' started.
t = 0.00s Start Test at 2016-12-20 09:58:02:209
t = 0.01s Set Up

我去 github 的 WebDriverAgent 下载安装了最新的版本,测试后一样有这个问题,我猜测 WebDriverAgent 目前不支持 IOS10 最近几个新版本的真机运行。

#1 楼 @meil000 搞不定啊 只能等等其他大神了

@ 楼主,请问你解决了吗?我也遇到这个一模一样的问题,研究了 2 天还没有解决,环境是 appium1.6.3+xcode8.2+ios10.2iphone6P 真机。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册