1、下载或者更新Homebrew:homebrew官网 macOS 不可或缺的套件管理器
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" #下载
$ brew update #更新
$ brew -v
Homebrew 1.1.5
Homebrew/homebrew-core (git revision e151b; last commit 2016-12-26)
2、使用homebrew来安装node.js : Node.js教程 node采用C++编写,是一个JavaScript的运行环境,因为JS是脚本语言需要一个解析器才能运行,对于写在HTML页面的JS,浏览器本身就是解析器,对于需要单独运行的JS,Node.js就是解析器。
$ brew install node
$ node -v
v7.3.0
3、安装npm: NPM 使用介绍 是一个NodeJS包管理和分发工具,已经成为了非官方的发布Node模块(包)的标准。
$ brew install npm
4、使用npm来安装appium,2017/01/03目前最新的版本是 1.6.3 ,当然也可以在 Macos下bitbucket下载appium客户端,但是坑人的是最新版本是 1.5.3 支持的还只是 iOS10 以下的 UIAutomation 框架基础上测试,而 iOS10 以后苹果使用的却是基于 XCUITest ,所以只能采用npm安装咯。但是因为国内墙太高而使用npm却是从国外服务器下载,有时候使用npm需要非常长的时间,更多时候是失败,推荐使用cnpm来安装:淘宝 NPM 镜像 10分钟同步npmjs.org镜像,使用方式和npm完全一致
$ npm install cnpm -g --registry=https://registry.npm.taobao.org
$ npm view appium versions #查看appium所有的版本号
5、使用cnpm安装appium和appium-doctor:
$ cnpm install -g appium --no-cache
$ cnpm install -g appium
$ cnpm install -g appium-doctor
6、检查appium环境检测:
$ appium-doctor
info AppiumDoctor Appium Doctor v.1.2.5
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
WARN AppiumDoctor ✖ Xcode Command Line Tools are NOT installed!
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
info AppiumDoctor ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor ✔ HOME is set to: /Users/denglibing
WARN AppiumDoctor ✖ ANDROID_HOME is NOT set!
info AppiumDoctor ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
WARN AppiumDoctor ✖ adb could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor ✖ android could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor ✖ emulator could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor ✖ Bin directory for $JAVA_HOME is not set
info AppiumDoctor ### Diagnostic completed, 6 fixes needed. ###
info AppiumDoctor
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor - Manually configure ANDROID_HOME.
WARN AppiumDoctor - Manually configure ANDROID_HOME and run appium-doctor again.
WARN AppiumDoctor - Add '$JAVA_HOME/bin' to your PATH environment
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye, run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor
常见问题解决:
✖ Xcode Command Line Tools are NOT installed!
$ xcode-select --install #按照提示安装即可
✖ Carthage was NOT found!
$ brew install carthage #carthage:类似cocoapods管理第三方代码,自动将工程编译为动态库,所以仅支持iOS8以上
WARN AppiumDoctor ✖ ANDROID_HOME is NOT set!
但是建议安装安装编译器,可以解决其他Android环境的其他问题 AndroidStudio(https://developer.android.com/studio/index.html?hl=zh-cn)
设置 ANDROID_HOME 路径:
http://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x
设置 JAVA_HOME 路径:
http://stackoverflow.com/questions/6588390/where-is-java-home-on-osx-sierra-10-12-el-captain-10-11-yosemite-10-10
JAVA_HOME问题:
当前最新JDK版本下载地址 Java SE Development Kit 8u111 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
.bash_profile文件:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
export ANDROID_HOME=/Users/denglibing/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:${JAVA_HOME}/bin
7、安装appium客户端,上面的操作只是安装了server端,接下来需要安装测试代码运行所依赖的客户端,我们以python为例:
git clone https://github.com/appium/python-client
cd python-client
#谢谢 @GentHuang 提醒
sudo python setup.py install
8、对于 iOS10 以上的测试,需要下载安装 appium-xcuitest-driver 驱动:Appium iOS driver, backed by Apple XCUITest , 当然也可以在 /usr/local/lib/node_modules/appium/node_modules/.2.5.1@appium-xcuitest-driver/WebDriverAgent/ 找到该项目,执行 carthage update , 选择 WebDriverAgentRunner 这个target编译即可。
其他相关的安装:
$ ./Scripts/bootstrap.sh #感谢网友 @托托李_742f 的提醒,添加该命令解决很多人编译WebDriverAgent不通过的问题。
$ brew install libimobiledevice --HEAD # install from HEAD to get important updates
$ brew install ideviceinstaller # 只是对iOS9有用
$ npm install -g ios-deploy # iOS10 以后的版本安装ios-deploy
$ sudo gem install xcpretty # 真机需要安装 xcpretty
不太熟悉WebDriverAgent的可以看看这个博客:
https://testerhome.com/topics/7220
9、下载测试代码并且测试,官网上的测试代码坑很多,这个问题我困扰我好久。一开始还以为是自己那个环境出问题还是流程不对,结果真的只是官网测试代码本身问题,当然可以自己编写代码测试咯,也可以下载我的一个简单的 erduoniba/appium_ios_sample_code
先启动 appium 服务器:
$ appium &
再执行模拟器的python客户端的代码测试
$ cd sample-code/apps/HHH
#在sample-code/apps/HHH/build/Release-iphonesimulator/得到HHH.app包
$ xcodebuild -sdk iphonesimulator
Build settings from command line:
SDKROOT = iphonesimulator10.2
=== BUILD TARGET HHH OF PROJECT HHH WITH THE DEFAULT CONFIGURATION (Release) ===
...
...
...
Signing Identity: "-"
/usr/bin/codesign --force --sign - --timestamp=none /Users/denglibing/Desktop/sample-code/apps/HHH/build/Release-iphonesimulator/HHH.app
** BUILD SUCCEEDED **
$ cd sample-code/examples/python
$ python ios_simple_simulator.py # 执行测试脚本时,会遇到 HTMLTestRunner 错误的问题,这个是因为第二篇也对这个脚本进行了测试,请移步到 这里http://www.jianshu.com/p/a673b93d1f98 可以快速解决并输出测试结果
test_scroll (__main__.SimpleIOSTests) ... ok
----------------------------------------------------------------------
Ran 1 test in 30.421s
OK
对于真机,可能要麻烦些,安装 appium-xcuitest-driver 驱动后,生成在真机上运行的包:
参考资料可以看官网的说明 部署ios-app-到手机上
# 在 apps/HHH/build/Release-iphoneos/HHH.app 得到 release 包
$ xcodebuild -sdk iphoneos -target HHH -configuration Release CODE_SIGN_IDENTITY="iPhone Distribution: Shenzhen XXXX Technology Co., Ltd. (B9FH944VTE)"
PROVISIONING_PROFILE="08f04032-ca2e-4bb5-b1ba-c32778115f2e"
关于怎么设置 CODE_SIGN_IDENTITY 和 PROVISIONING_PROFILE 如何查看 ,可以选择下图所示的 Development Team 一行, control+c 然后 复制出去即可
所示的 Development Team 一行, control+c 然后 复制出去即可
接下来连上真机 执行测试用例代码:
$ cd sample-code/examples/python
$ python ios_simple_device.py
test_scroll (__main__.SimpleIOSTests) ... ok
----------------------------------------------------------------------
Ran 1 test in 30.421s
OK
10:一些很有帮助的资料
很好的论坛 https://testerhome.com
appium源码地址: https://github.com/appium/appium
appium官网地址:http://appium.io/
appium中文说明文档:http://appium.io/slate/cn/master/?ruby#about-appium
客户端安装:
http://appium.io/downloads.html
open .bash_.bash_profile
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
export JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
ANDROID_HOME=/Users/ocean/Library/Android/sdk
export ANDROID_HOME
export PATH=${PATH}:/Users/ocean/Library/Android/sdk/tools:/Users/ocean/Library/Android/sdk/platform-tools