iOS自动化之WDA(WebDriverAgent)安装及踩坑

Table of Contents

更新说明

一、WDA介绍

二、部署环境

三、安装步骤

1、安装基础依赖

2、下载WDA

3、执行bootstrap.sh

4、打开WebDriverAgent工程配置

5、编译执行WebDriverAgentRunner

四、安装完成检查



更新说明

facebook的WDA在iOS 10 时代苹果已经废弃了,目前依然在更新的是Appium官方的WDA,官方链接如下:

https://github.com/appium/WebDriverAgent

安装配置和facebook类似,配置好签名证书即可,不需要修改代码,也不需要修改Bundle ID

一、WDA介绍

WebDriverAgent 在 iOS 端实现了一个 WebDriver server ,借助这个 server 我们可以远程控制 iOS 设备。你可以启动、杀死应用,点击、滚动视图,或者确定页面展示是否正确。

特点:

  • Works with device & simulator
  • Implements most of WebDriver Spec
  • Implements part of Mobile JSON Wire Protocol Spec
  • USB support for devices
  • Inspector endpoint with friendly user interface to inspect current device state
  • Easy development cycle as it can be launched & debugged directly via Xcode
  • Unsupported yet, but works with tvOS & OSX

二、部署环境

OS: 10.15.6

Xcode: 11.7 (Build version 11E801a)

参考文档:https://github.com/facebookarchive/WebDriverAgent

三、安装步骤

1、安装基础依赖

brew install git

brew install carthage

2、下载WDA

执行命令:git clone https://github.com/facebookarchive/WebDriverAgent.git

3、执行bootstrap.sh

cd WebDriverAgent

./Scripts/bootstrap.sh

注:执行可能会报错,错误内容如下:

ERROR in ./js/app.js
Module parse failed: /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/js/app.js Unexpected token (67:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (67:6)

解决方法:修改WebDriverAgent/Inspector/webpack.config.js这个文件,删除下文“, exclude: /node_modules/ ”,再次执行sh

module: {
    loaders: [
      { test: /\.js?$/, loaders: ['babel-loader'], exclude: /node_modules/ }, 
      { test: /\.js?$/, loaders: ['babel-loader'] },
      { test: /\.css?$/, loader: 'style-loader!css-loader' },
    ]
  },

4、打开WebDriverAgent工程配置

使用Xcode打开WebDriverAgent这个工程,双击项目路径下WebDriverAgent.xcodeproj

(1)修改WebDriverAgentRunner这个项目的Bundle ID,这里可以自定义命名(注意id命名不能重复)

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第1张图片

(2)导入证书(由于我没有开发者证书,提供给开发组Bundle ID,借用导出的p12和依赖文件)

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第2张图片

注:这里使用提供的依赖文件编译依然失败,

错误信息:building WebDriverAgent is asking for a [设定的包名].xctrunner bundle ID

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第3张图片

解决方式:更换Team证书,参考如下链接:https://github.com/appium/appium/pull/14233

5、编译执行WebDriverAgentRunner

(3)选择Product -> Scheme -> WebDriverAgentRunner

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第4张图片

(4)选择Product -> Destination -> 连接的iOS手机名称(这里使用的真机)

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第5张图片

(5)运行运行Product -> Test,安装成功后手机上会出现WebDriverAgent的应用图标

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第6张图片

注1:在编译的过程中会报错,错误信息如下

1)Semantic issue: ‘assign‘ property of object type may become a dangling reference; consider using ‘unsafe_unretained‘
2)Parse Issue: Could not build module ‘RoutingHTTPServer‘

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第7张图片

解决方法:双击,进入到报错代码处,修改assign为unsafe_unretained,执行clean and build,错误就没有了

注2:Build成功后,执行Test会抛出异常,错误信息如下:

2020-06-12 19:57:31.235846-0700 WebDriverAgentRunner-Runner[1849:82950] Running tests...
Test Suite 'All tests' started at 2020-06-12 19:57:32.209
Test Suite 'WebDriverAgentRunner.xctest' started at 2020-06-12 19:57:32.212
Test Suite 'UITestingUITests' started at 2020-06-12 19:57:32.213
Test Case '-[UITestingUITests testRunner]' started.
    t =     0.00s Start Test at 2020-06-12 19:57:32.226
    t =     0.01s Set Up
2020-06-12 19:57:32.240001-0700 WebDriverAgentRunner-Runner[1849:82950] -[UITestingUITests internalImplementation]: unrecognized selector sent to instance 0x283250c30
    t =     0.05s     Assertion Failure: :0: failed: caught "NSInvalidArgumentException", "-[UITestingUITests internalImplementation]: unrecognized selector sent to instance 0x283250c30"
(

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第8张图片

问题原因是FBFailureProofTestCase中internalImplementation这个API在XCode11.4版本以后已经删除

解决方法:打开WebDriverAgent/WebDriverAgentLib/Utilities/FBFailureProofTestCase.m,修改26~36行,添加如下红色代码

  if ([self respondsToSelector:@selector(internalImplementation)]) {
      self.internalImplementation =
        (_XCTestCaseImplementation *)[FBXCTestCaseImplementationFailureHoldingProxy
                                      proxyWithXCTestCaseImplementation:self.internalImplementation];
    } else {
      self.shouldSetShouldHaltWhenReceivesControl = NO;
      self.shouldHaltWhenReceivesControl = NO;
    }

四、安装完成检查

由于国内手机设置需要转发下端口,命令行执行:iproxy 8300 8100

然后再浏览器里请求:http://localhost:8300/,如果返回一串json字符,那么WDA安装成功了

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第9张图片

http://localhost:8300/status可以查看当前设备的状态,获取与wda通信session id

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第10张图片

http://localhost:8300/inspector 打开WDA 的inspector,在该界面点击home则手机返回主页面

iOS自动化之WDA(WebDriverAgent)安装及踩坑_第11张图片

 

 

你可能感兴趣的:(IOS,mac,os,x,WDA,iOS,iOS自动化测试,WebDriverAgent)