mac下Appium环境配置

一、Appium环境搭建
1、xcode(需要OS X版本支持):
下载对应版本的xcode(支持对应手机系统),解压,拖入应用程序。
2、安装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使用的开发者证书)
3、检测appium环境:
终端输入:appium-doctor
4、启动appium桌面程序:
启动Appium。在运行自动化测试脚本前一定要先运行Appium,启动测试应用。
1)通过下面的两种方式启动appium服务器。(appium启动会先启动webdriveragent,启动之后不要将webdriverAgent关闭,否则再次启动appium会报错)
方式1、通过命令行安装的appium可以通过终端启动,终端输入:appium,看到终端打印出下面日志,表示服务器启动成功。
 
方式2、已经安装了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等和坐标。支持录制脚本。
 
二、安装及运行过程中遇到的坑
坑1、
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参数
 
坑2、
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
 
坑3、
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
 
 
 
posted @ 2018-02-04 22:39  小白爷  阅读(10882)  评论(0编辑  收藏  举报