mac下Appium环境配置

1、Appium环境搭建
一、xcode(须要OS X版本支持):
下载对应版本的xcode(支持对应手机系统),解压,拖入应用程序。
二、安装appium:
安装node、brew、nmp、carthage等: http://www.jianshu.com/p/efa9ac4900a6
1)若是有旧版本的appium,须要先卸载旧版本的appium:npm uninstall -g appium
2)下载appium1.6.5正式版: https://github.com/appium/appium/releases/tag/v1.6.5,终端进入文件目录,命令行安装:npm install。
      验证安装成功:终端输入“appium -v”,出现版本号表示安装成功。
  此处有坑:appium-desktop 1.6.4及如下不支持xcode9.0.1,(请注意本身的xcode版本和appium版本,要否则会报错)
3)与系统进行关联:npm link
4)安装appium桌面程序: https://github.com/appium/appium-desktop/releases/tag/v1.2.0,下载zip包,解压,拖入应用程序。
5)Appium自带的WebDriverAgent存在bug,改使用FaceBook的WebDriverAgent(WebDriverAgent下载: https://github.com/facebook/WebDriverAgent/):
从git上下载WebDriverAgent,进入/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent 目录,命令行运行:./Scripts/bootstrap.sh,下载依赖,而后将该文件替换appium应用中的WebDriverAgent(目录:/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent )
使用xcode打开WebDriverAgent程序,在真机上安装WebDriverAgent程序,手机上出现WebDriverAgent应用表示安装成功。(在通用-> 描述文件文件中信任xcode使用的开发者证书)
三、检测appium环境:
终端输入:appium-doctor
四、启动appium桌面程序:
启动Appium。在运行自动化测试脚本前必定要先运行Appium,启动测试应用。
1)经过下面的两种方式启动appium服务器。(appium启动会先启动webdriveragent,启动以后不要将webdriverAgent关闭,不然再次启动appium会报错)
方式一、经过命令行安装的appium能够经过终端启动,终端输入:appium,看到终端打印出下面日志,表示服务器启动成功。
 
方式二、已经安装了appium桌面程序能够经过启动桌面程序来启动appium服务器。打开程序看到以下页面:
 
 
直接点击Start Server便可启动appium服务器,跟终端命令行启动打印出的日志同样,以下所示:
 
 
上图三个红色框分别表示:①查看应用元素(inspector)②保存日志文件③中止appium服务器。
启动了appium服务器以后。能够直接运行自动化。
)配置一些Desired Capabilities信息:
 
 
默认会以127.0.0.1ip和4723端口启动一个session,若是要启动多个session,能够经过修改端口号的方式:点击Custom Server,服务器ip输入127.0.0.1,端口输入一个目前未在使用的端口号就能够了。
通常须要填写的参数有platformName(平台)、platformVersion(平台版本)、udid(设备的udid,填错不能启动应用)、deviceName(设备名称)、bundleid(应用的bundleid)、automationName(必须填写XCUITest,不写默认是UIAutomation的方式,该方式不支持IOS10)。
要链接iOS真机,必须打开真机的开发者模式。
而后选中要启动的已经配置好的信息,点击Start Session。看到下面的画面表示启动成功,能够查看元素的accessibility_id、xpath、value等和坐标。支持录制脚本。
 
2、安装及运行过程当中遇到的坑
坑一、
A new session could not be created. Details: Appium's IosDriver does not support xcode version 8.3.3.
Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead.
解决方案:
在--capability添加automationName=XCUITest参数
 
坑二、
AssertionError: Message: An unknown server-side error occurred while processing the command.
Original error: Unknown device or simulator UDID: '***'
解决方案:
Appium使用idevice_id(libimobiledevice的一部分)来肯定设备的可用性
brew install libimobiledevice --HEAD
 
坑三、
AssertionError: Message: An unknown server-side error occurred while processing the command. Original error: 
Could not initialize ios-deploy make sure it is installed (npm install -g ios-deploy) and works on your system
解决方案:
安装ios-deploy
npm install -g ios-deploy
 
坑5:
appium-desktop 1.6.4及如下不支持xcode9.0.1,须要升级appium
 
坑6:
webdriverAgent安装失败
解决方案:
从新编译webdriverAgent,参考地址
 
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=3825bba08e5c10c499ddaf0276bac01983ab7119' test