1.安装brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
若访问被拒绝,可参考https://www.jianshu.com/p/2e98d711ea4d
2.安装xcode
直接在app store下载
安装完成后在终端运行xcodebuild,此时我出现报错“xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance”,是因为xcodebuild的路径不正确
查看路径:
$ xcode-select --print-path /Library/Developer/CommandLineTools
切换路径:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
再次查看路径:
$ xcode-select --print-path /Applications/Xcode.app/Contents/Developer
3.安装libimobiledevice、ideviceinstaller、usbmuxd
step1.brew uninstall -f libimobiledevice ideviceinstaller libusbmuxd
step2.brew install -v --fetch --build-from-source libusbmuxd libimobiledevice ideviceinstaller
检查是否安装成功,在终端输入idevicedate(查看设备时间),由于我没有连设备,如下就是安装成功了。
$ idevicedate No device found.
如果提示
$ idevicedate -bash: idevicedate: command not found
则是没安装成功,根据具体报错重新执行命令安装
4.安装nodejs
让安装使用清华大学的镜像
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
安装nodejs
brew install nodejs
安装完成后运行 npm -v、node -v如果显示了版本号说明安装成功
若之前已安装过nodejs,运行npm可能会报错,此时建议直接删除node重新安装,比看半天报错要快。。删除可参考 Mac彻底卸载node
5.安装appium、appium-doctor和appium桌面版,另外现在appium-inspector已经拆分出来了,需要单独安装
npm install -g appium
npm install -g appium-doctor
使用appium-doctor检查Appium iOS环境
appium-doctor --ios
appium桌面版下载
若打开appium gui时提示无法验证app是否安全,则在终端执行
xattr -cr "/Applications/Appium Server GUI.app"
再次尝试打开,此时又报错:Uncaught Exception:
Error: Could not get code signature for running application
再次执行:
codesign --deep --force --verbose --sign - /Applications/Appium\ Server\ GUI.app
ok,打开了。。
appium-inspector桌面版下载
xattr -cr "/Applications/Appium Inspector.app"
6.安装xcpretty,xcpretty是一个用 ruby 实现的工具,作用是美化 xcodebuild 输出。
sudo gem install xcpretty
7.安装Carthage,Carthage为用户管理第三方框架和依赖。后续编译webDriverAgent就需要用到。
brew install carthage
8.安装ios-webkit-debug-proxy,借助 ios_webkit_debug_proxy,Appium可以在iOS真机上访问webview。
brew install ios-webkit-debug-proxy
9.安装appium-xcuitest-driver依赖
进入appium wda目录下
cd /Applications/Appium\ Server\ GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
执行
mkdir -p Resources/WebDriverAgent.bundle
./Scripts/bootstrap.sh -d
10.配置xcode
1.在https://developer.apple.com/account/注册一个开发者账号,usb连好手机,把手机开发者模式打开。
- 打开Xcode,file - open - command+shift+g - 输入路径“Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj”,打开。(这个路径必须是appium自带的WebDriverAgent !!不要随便替换自己下载的其他WDA文件,不然查问题查到疯!!如果最后通过appium inspector创建会话失败,可能就是这个文件的问题)
3.Product - Scheme - 选择WebDriverAgentRunner
4.修改WebDriverAgentLib和WebDriverAgentRunner的配置
5.点左上角播放图标build,这一步会遇到不同的报错,具体问题具体分析,直到build成功。
build xcode时遇到的报错:
1)'RoutingHTTPServer/RouteResponse.h' file not found
解决方法:进入WebDriverAgen目录下,下载依赖
cd /Applications/Appium\ Server\ GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
./Scripts/bootstrap.sh
下载依赖有报错先忽略。
此时重新编译就不会报这个错了。
2)cannot link directly with dylib/framework, your binary is not an allowed client of /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework/XCTAutomationSupport for architecture arm64
解决方法:替换XCTAutomationSupport.framework文件
11.测试WebDriverAgent
xcode build成功后,选择product - test,会在手机上安装WebDriverAgent
此时若Mac提示无法启动WebDriverAgentRunner,需要在手机中 通用 - VPN与设备管理(或描述文件与设备管理) 里信任开发者APP,然后再次product - test。
ok,此时我又报错了。。正常情况下此时在xcode控制台应该能看到如下信息:
WebDriverAgentRunner-Runner[602:24965]
ServerURLHere->http://169.254.147.85:8100<-ServerURLHere
但我报了个错:UITestingUITests internalImplementation]: unrecognized selector sent to ...
参考解决方法:我是通过注释第26行代码解决的
总之,能看到ServerURLHere就可以了。
在mac浏览器中输入ServerURLHere中间的http://IP地址:端口/status,看到返回一串json,那WDA就是正常可用了~,如果网页访问不了,尝试如下操作:
终端:iproxy 8100 8100,出现waiting for connection
浏览器输入:http://localhost:8100/status
看到返回一串json,ok
12.安装appium-python-client(python和appium通信的工具)
pip3 install appium-python-client(事先需要装好python和pip)
13.appium-Inspector启动参数配置
Remote Path:/wd/hub
Desired Capabilities
{
"platformName": "ios",
"appium:platformVersion": "12.5.5",
"appium:bundleId": "com.xx",
"appium:deviceName": "iPhone 5s",
"appium:udid": "16769514ba8a78b9cd8743ea",
"appium:noReset": "true",
"appium:automationName": "XCUITest",
"appium:newCommandTimeout": "10000"
}
其中,
bundleId获取:ideviceInstaller -l
udid(设备标识)获取:idevice_id -l