Appium for mac 环境配置

安装Nodejs

1、安装包安装下载安装Nodejs

在mac 下的安装目录如下

· Node.js v8.11.1 to /usr/local/bin/node

· npm v5.6.0 to /usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH. 安装完之后,可使用node -v 查看node 版本

2、brew 安装

brew install nodebrew install node

 

安装xcode

1、在商城中搜索并安装。

安装JDK与SDK

1、JDK 安装包安装

下载安装JDK,双击dmg 安装,并配置环境变量。

 

2、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,如图:

iOS 检测debug和线上环境 ios测试环境搭建_自动化测试

 

保持默认的选项即可,点击Install 23 packages…。进入到下图:

iOS 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_02

方法1:点击桌面空白位置然后使用快捷键shift+cmd+G,输入~/.bash_profile, 找到.bash_profile 文件,打开后在该文件中添加:

Exprot JAVA_HOME=$(/usr/libexec/java_hone)

Exprot ANDROID_HOME=/usr/local/android-sdk-macox

iOS 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_03

终端执行source ~/.bash_profile 使环境变量生效。

 

安装Appium

 

Appium 可使用安装包和npm 安装

 

1、安装包安装

 

下载安装Appium-desktop 客户端,双击dmg 安装

 

2、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 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_04

 

iOS 真机环境配置

真机运行iOS 测试,需要安装两个软件

1、安装libimobiledevice,这是用于连接iOS 设备的开源工具,类似于Android 的ADB

brew install libimobiledevice --HEAD

2、安装ios-deploy,这是支持使用命令行管理iOS 设备app 的工具

npm install -g ios-deploy

 

基本配置

 

安装WebDriverAgent 到真机

 

下方为整理的配置,官网详情配置请参考这里

 

1、将真机连接电脑

 

2、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 放入原来的路径下

 

3、双击WebDriverAgent.xcodeproj 打开WebDriverAgent 工程

 

5、设置签名证书(这里使用免费App Id 的自签名证书):

 

6、打开工程TARGETS,选择WebDriverAgentLib->General,修改Bundle Identify 为

 

com.yfm.wad.lib(任意修改)

 

iOS 检测debug和线上环境 ios测试环境搭建_iOS_05

iOS 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_03

7、选择IntegrationApp->General,修改Bundle Identify 为

iOS 检测debug和线上环境 ios测试环境搭建_iOS_07

iOS 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_03

8、选择WebDriverAgentRunner->Build Settings,修改Bundle Identify 为com.yfm.WebDriverAgentRunner

iOS 检测debug和线上环境 ios测试环境搭建_自动化测试_09

证书设置完之后,使用command+U 运行WebDriverAgentRunner 到真机上 

iOS 检测debug和线上环境 ios测试环境搭建_ide_10

运行完之后,真机上会多个WebDriverAgentRunner 的App,App 启动之后马上退出,这是正常的控制台会输出如下信息:

 

启动设置

 

1、打开Appium 桌面客户端

iOS 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_11

点击Start Server 启动Appium 服务端

2、设置Desired Capabilities,运行测试

iOS 检测debug和线上环境 ios测试环境搭建_iOS 检测debug和线上环境_03

点击Appium 桌面端右上角的搜索按钮,设置Desired Capabilities

iOS 检测debug和线上环境 ios测试环境搭建_ios_13

 

点击 Appium 桌面端右上角的搜索按钮,设置 Desired Capabilities

iOS 检测debug和线上环境 ios测试环境搭建_iOS_14

参数说明:

{

 

"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 窗口

iOS 检测debug和线上环境 ios测试环境搭建_ios_15

图片为虚拟机效果,真机链接成功后也会出现inspctor 界面。

 

附录:

 

IOS 查看本机的udid 方式:

 

a) 在iTunes 上,本机的信息上查看。

iOS 检测debug和线上环境 ios测试环境搭建_自动化测试_16

 

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运行(会生成测试报告)。

 

生成的报告:

iOS 检测debug和线上环境 ios测试环境搭建_ios_17

龙测科技,您身边的测试专家。