appium1.15.1-IOS真机自动化环境配置WDA

目录

安装环境:

Appium必须安装jdk和sdk

appium版本1.15.1 (1.15.1.20191013.2)

brew安装慢-替换更新源

Brew安装之前折腾过不少

brew重置更新源-换回官方源的需求

brew完成更新源的更换后升级

WDA安装前需要的依赖:

WDA基本(手工)配置

./Scripts/bootstrap.sh -d问题解决:

Please make sure that you have Carthage installed

No JSON object could be decoded

检测成功提示:

用Xcode打开WebDriverAgent.xcodeproj

Could not determine Xcode version-解决办法

xcodebuild failed with code 65 error解决

解决NSInvalidArgumentException错误:


安装环境:

电脑:MacbookPro-OS-10.15.7

设备:iphone6s - ios12.2

appum:1.15.1-desktop

 

Appium必须安装jdksdk

根据官方文档的描述,sdk保留文件目录:

SDK Tools 必须

SDK Platform-tools 必须

SDK Platform必须至少安装一个版本(最新)

System Image建议安装

Android Support建议安装

SDK Samples建议安装

 

 

appium版本1.15.1 (1.15.1.20191013.2)

/Applications/Appium.app/Contents/Resources/app/node_modules/appium-webdriveragent

 

brew安装慢-替换更新源

# 替换brew.git:
$ cd "$(brew --repo)"
# 中国科大:
$ git remote set-url origin
https://mirrors.ustc.edu.cn/brew.git
# 清华大学:
$ git remote set-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 替换homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 中国科大:
$ git remote set-url origin
https://mirrors.ustc.edu.cn/homebrew-core.git
# 清华大学:
$ git remote set-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

# 替换homebrew-bottles:
# 中国科大:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 清华大学:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 应用生效:
$ brew update

 

Brew安装之前折腾过不少

导致你的Homebrew有点问题,那么可以尝试使用如下方案:

# 诊断Homebrew的问题:
$ brew doctor

# 重置brew.git设置:
$ cd "$(brew --repo)"
$ git fetch
$ git reset --hard origin/master

# homebrew-core.git同理:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git fetch
$ git reset --hard origin/master

# 应用生效:
$ brew update 

brew重置更新源-换回官方源的需求

# 重置brew.git:
$ cd "$(brew --repo)"
$ git remote set-url origin https://github.com/Homebrew/brew.git

# 重置homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://github.com/Homebrew/homebrew-core.git

 

brew完成更新源的更换后升级

$ brew upgrade将现有的软件进行更新至最新版本,这样便能很直接的看出速度上的变化了。最后不要忘记$ brew cleanup将旧有的软件安装包进行清理

brew 安装更新成功后可以安装ios的相关依赖.

WDA安装前需要的依赖:

  1. Appium iOS真机测试依赖于中心第三方软件套件:libimobiledevice, 用homebrew很容易安装

brew install libimobiledevice

  1. 除了依赖libimobiledevice以外, Appium支持真机在iOS 9.3以上版本使用Xcode 8+ 还要依赖于ios-deploy,通过npm和homebrew很容易安装:

npm install -g ios-deploy

brew install ios-deploy

  1. (对于hybrid或者web测试, 还需要遵循ios-webkit-debug-proxy设置指令)

XCUITest driver工作方式是在真机上安装一个名为WebDriverAgent-Runner的助手应用程序, 通过该应用程序,测试应用程序是自动化的。虽然这在理论上是简单的,但是开发和测试的代码签名和配置文件的环节可能会让人有点头疼。

 

WDA基本(手工)配置

WebDriverAgent目录:

/usr/local/n/versions/node/10.4.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

* 找到appium的安装盘:

    $ which appium

    /usr/local/n/versions/node/10.4.0/bin/appium 用n管理器安装的node指向

    ->/usr/local/n/versions/node/10.4.0/lib/node_modules/appium/build/lib/main.js

* 进入appium安装盘:/path/where/installed/bin/appium, 在以下路径下找到WebDriverAgent

    /usr/local/n/versions/node/10.4.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

* 打开terminal到上面的目录下, 执行以下命令来配置项目:

    $ mkdir -p Resources/WebDriverAgent.bundle

    $ ./Scripts/bootstrap.sh -d

 

 

 

./Scripts/bootstrap.sh -d问题解决:

Please make sure that you have Carthage installed

MacBookPro-AutoPC:appium-webdriveragent user$ ./Scripts/bootstrap.sh -d

Fetching dependencies

Please make sure that you have Carthage installed (https://github.com/Carthage/Carthage)

Note: We are expecting that carthage installed in /usr/local/bin/

MacBookPro-AutoPC:appium-webdriveragent user$ brew install carthage

==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/carthage-0.

######################################################################## 100.0%

==> Pouring carthage-0.36.0.catalina.bottle.tar.gz

==> Caveats

Bash completion has been installed to:

  /usr/local/etc/bash_completion.d

 

zsh completions have been installed to:

  /usr/local/share/zsh/site-functions

==> Summary

🍺  /usr/local/Cellar/carthage/0.36.0: 8 files, 7.6MB

 

No JSON object could be decoded

 ./Scripts/bootstrap.sh -d

Fetching dependencies

xcrun: error: unable to find utility "simctl", not a developer tool or in PATH

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 291, in load

    **kw)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads

    return _default_decoder.decode(s)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode

    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode

    raise ValueError("No JSON object could be decoded")

ValueError: No JSON object could be decoded

 

解决方案就是去xcode设置里面,将Command line Tools设置一下,在Xcode>preferences>Locations里面,设置之后再运行终端即可

 

 

检测成功提示:

MacBookPro-AutoPC:appium-webdriveragent user$ ./Scripts/bootstrap.sh -d

Fetching dependencies

*** Checking out RoutingHTTPServer at "v1.0.2"

*** Checking out CocoaAsyncSocket at "7.6.3"

*** Checking out YYCache at "1.1.0"

*** Cloning RoutingHTTPServer

*** Cloning CocoaAsyncSocket

*** Cloning YYCache

*** xcodebuild output can be found in /var/folders/bz/wtzgm7wj1z3gv0x22j51rrnm0000gn/T/carthage-xcodebuild.cBTMBE.log

*** Downloading CocoaAsyncSocket.framework binary at "Version 7.6.3"

*** Building scheme "RoutingHTTPServer tvOS" in RoutingHTTPServer.xcodeproj

*** Building scheme "RoutingHTTPServer iOS" in RoutingHTTPServer.xcodeproj

*** Building scheme "YYCache iOS" in YYCache.xcodeproj

*** Building scheme "YYCache tvOS" in YYCache.xcodeproj

 

Xcode打开WebDriverAgent.xcodeproj

  1. 以下2个目标在"General"选项卡下都选"Automatically manage signing"并选择你的Development Team,应该会自动选择Signing Ceritificate.

如下图所示: WebDriverAgentLib、WebDriverAgentRunner

如果Signing Provisioning profile失败则需要先去Build Settings选项卡下面把bundle Id修改成xcode接受的bundle id

 

 

  1. 返回到WebDriverAgentRunner 目标下的"General" 选项卡, 应该可以看到创建了一个provisioning profile如下图:

 

修改开发者账号后,选中webDriverAgent项目,WebDriverAgentRunner配置Signing&Capabilities:

 

 

Build的前记得Xcode:Product->Clean Build Folder

 

Could not determine Xcode version-解决办法

Appium启动ios手机时遇到问题:Could not get Xcode version. /Library/Developer/Info.plist does not exist on disk.

正在使用命令行Appium。要解决该问题,您必须将Xcode切换到正确的路径。

以下命令将有所帮助:

  sudo xcode-select --switch /Applications/Xcode.app

xcodebuild failed with code 65 error解决

An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65 xcodebuild error message: . Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.

重启手机电脑后,发现自己在电脑上之前使用过airtest的WDA,所以端口号可能占用了,需要把端口号改掉。

 

  1. 最后 Build the project:

    xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=<udid>' test

 

* 如果成功的话,会看到类似如下的输出:

    Test Suite 'All tests' started at 2017-01-23 15:49:12.585

    Test Suite 'WebDriverAgentRunner.xctest' started at 2017-01-23 15:49:12.586

    Test Suite 'UITestingUITests' started at 2017-01-23 15:49:12.587

    Test Case '-[UITestingUITests testRunner]' started.

        t =     0.00s     Start Test at 2017-01-23 15:49:12.588

        t =     0.00s     Set Up

* 为了完成验证, 你可以尝试访问WebDriverAgent服务的状态 (注意: 必须跟手机设备在同一个网络下, 并且要知道它的IP地址:Settings => Wi-Fi => Current Network):

    export DEVICE_URL='http://<device IP>:8100'

 

 

 

 

 

解决NSInvalidArgumentException错误:

Test failed时遇到的错误

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: <unknown>:0: failed: caught "NSInvalidArgumentException", "-[UITestingUITests internalImplementation]: unrecognized selector sent to instance 0x283250c30"

 

问题原因是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.shouldHaltWhenReceivesControl = NO;

    }

 

注意:因为airtestappium都需要使用WDA,airtest在其他地方已经使用了8100端口号,需要将appium的端口号改成其他未被占用的端口(如:8200)即可成功安装wda并启动app

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值