Appium for mac 环境配置
安装Nodejshtml
一、安装包安装下载安装Nodejsjava
在mac 下的安装目录以下node
· Node.js v8.11.1 to /usr/local/bin/nodeandroid
· npm v5.6.0 to /usr/local/bin/npmios
Make sure that /usr/local/bin is in your $PATH. 安装完以后,可以使用node -v 查看node 版本git
二、brew 安装github
brew install nodebrew install nodeweb
安装xcodemacos
一、在商城中搜索并安装。npm
安装JDK与SDK
一、JDK 安装包安装
下载安装JDK,双击dmg 安装,并配置环境变量。
二、SDK 安装下载Android SDK,测试Android App 须要。
下载地址:https://developer.android.com/studio/index.html#downloads
解压缩到任意位置,好比/usr/local/android-sdk-macosx,
运行/usr/local/android-sdk-macosx/tools/android,便可启动Android SDK Manager,如图:
保持默认的选项便可,点击Install 23 packages…。进入到下图:
方法1:点击桌面空白位置而后使用快捷键shift+cmd+G,输入~/.bash_profile, 找到.bash_profile 文件,打开后在该文件中添加:
Exprot JAVA_HOME=$(/usr/libexec/java_hone)
Exprot ANDROID_HOME=/usr/local/android-sdk-macox
终端执行source ~/.bash_profile 使环境变量生效。
安装Appium
Appium 可以使用安装包和npm 安装
一、安装包安装
下载安装Appium-desktop 客户端,双击dmg 安装
二、npm 安装
npm install -g appium
验证安装
使用appium-doctor 校验Appium 的依赖环境是否正确配置,使用下面命令安装appium-doctor
npm install -g appium-doctor
安装appium-doctor 可能提示没有权限,若是提示Error: EACCES: permission denied, access '/usr/local/lib/node_modules'错误,可以使用sudo npm install -g appium-doctor 命令安装
若是不想使用sudo 安装,可经过修改目录的读写权限,使用sudo chmod -R 777
/usr/local/lib/node_modules,而后执行npm install -g appium-doctor 来安装
sudo chomod -R 777 [path] 修改目录的权限为读和写以及执行
安装完appium-doctor 后,使用appium-doctor --ios 校验ios 环境,使用appium-doctor --android 校验安卓环境
iOS 真机环境配置
真机运行iOS 测试,须要安装两个软件
一、安装libimobiledevice,这是用于链接iOS 设备的开源工具,相似于Android 的ADB
brew install libimobiledevice --HEAD
二、安装ios-deploy,这是支持使用命令行管理iOS 设备app 的工具
npm install -g ios-deploy
基本配置
安装WebDriverAgent 到真机
下方为整理的配置,官网详情配置请参考这里
一、将真机链接电脑
二、WebDriverAgentRunner 的处理: 先使用 mac 打开终端
a) cd ~
b) 下载WebDriverAgent 项目最新的代码:
git clone https://github.com/facebook/WebDriverAgent
c) cd /Users/yourname/WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
d) 执行./Scripts/bootstrap.sh
e) cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver
f) rm –rf WebDriverAgent 删除自带的WebDriverAgent
g) ln –s ~/WebDriverAgent WebDriverAgent 将最新的WebDriverAgent 放入原来的路径下
三、双击WebDriverAgent.xcodeproj 打开WebDriverAgent 工程
五、设置签名证书(这里使用免费App Id 的自签名证书):
六、打开工程TARGETS,选择WebDriverAgentLib->General,修改Bundle Identify 为
com.yfm.wad.lib(任意修改)
七、选择IntegrationApp->General,修改Bundle Identify 为
八、选择WebDriverAgentRunner->Build Settings,修改Bundle Identify 为com.yfm.WebDriverAgentRunner
证书设置完以后,使用command+U 运行WebDriverAgentRunner 到真机上
运行完以后,真机上会多个WebDriverAgentRunner 的App,App 启动以后立刻退出,这是正常的控制台会输出以下信息:
启动设置
一、打开Appium 桌面客户端
点击Start Server 启动Appium 服务端
二、设置Desired Capabilities,运行测试
点击Appium 桌面端右上角的搜索按钮,设置Desired Capabilities
点击 Appium 桌面端右上角的搜索按钮,设置 Desired Capabilities
参数说明:
{
"platformName": "ios", // 运行平台"deviceName": "iPhone 8", // 设备名"platformVersion": "10.3.3", // 系统版本
"bundleId": "com.apple.mobilesafari", // App bundleId,这里使用 iOS 自带的 safari 浏览器
"udid": "xxxxxx" //真机则填入 udid,虚拟机可不填写。
}
点击Start session,开始测试
appium 会启动iOS 设备上的Safari 浏览器,并弹出appium inspector 窗口
图片为虚拟机效果,真机连接成功后也会出现inspctor 界面。
附录:
IOS 查看本机的udid 方式:
a) 在iTunes 上,本机的信息上查看。
IOS 真机查看本机的应用的Bundle id:
只须要安装brew install ideviceinstaller,而后运行ideviceinstaller -l 就能够了。
可是若是遇到Could not connect to lockdownd. Exiting.这种错误。采用下面的方法亲测可行。
brew uninstall ideviceinstaller brew uninstall libimobiledevice
brew install --HEAD libimobiledevice brew link --overwrite
libimobiledevice brew install ideviceinstaller brew link --overwrite ideviceinstaller
运行测试用例的项目搭建步骤
1. 从网站上下载模板longce-appium.zip。
2. 安装idea或Eclipse,并打开刚下载的运行模板,maven项目会自动下
载所须要的 jar 包。
3. 网站上把运行完的测试用例下载下来,在c:\longce-appium\src\test\java下面,按照测试代码的package创建文件夹,好比c:\longce-appium\src\test\javaxiaowokeji\test1,而后把zip包放到此目录下解压。
4. Appium参数介绍
在BaseTest.java文件下,设置IOS的相关启动项。(后续版本更新,会自动将web页面上的配置加载到运行环境中。)
5. 链接手机至PC,并启动Appium 服务(注:服务地址要与初始化代码中的地址保持一致)。
6. 选中测试方法并执行,或使用testNG.Xml运行(会生成测试报告)。
生成的报告:
龙测科技,您身边的测试专家。
官网:http://www.dragontesting.cn