MAC电脑下Appium + python3.6.8 + robotframework ios的真机测试环境搭建
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
本人的环境搭建的情况,MAC电脑一台(macOS Mojave 10.14.4),Xcode 10.2.1 ,自己注册的一个Apple ID 账户,必须你的电脑能连接互联网,最好不要用公司的网络,限制太多,容易掉坑里。
1.安装Homebrew
安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
卸载
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
2.安装 libimobiledevice (得先安装Homebrew)
brew install libimobiledevice
其实,libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备。
3.安装 ideviceinstaller(真机安装相关)
brew install ideviceinstaller
libimobiledevice中并不包含ipa的安装命令,所以还需要安装ideviceinstaller
4.安装 carthage , WDA编译时需要的依赖包。
brew install carthage
5.安装 node
(目的是安装 npm)官方下载地址https://nodejs.org/en/download/,下载.pkg 文件安装(LTS版本)
6.安装 iOS-deploy
npm install -g ios-deploy
7.安装 xcpretty
gem install xcpretty
8. Appium 桌面端下载安装(选择 dmg 文件)
https://github.com/appium/appium-desktop/releases
9.安装Appium doctor
npm install -g appium-doctor
主要时检查环境的配置情况
10.安装 webpack
npm i -g webpack
11.安装 wd
npm install -g wd (-g表示全局安装)
12.运行 Appium-doctor --ios

13.编译 WebDriverAgent
a. 在安装完Appium Destop ,从 https://github.com/appium/WebDriverAgent 下载的WebDriverAgent文件夹 ,替换路径/Application/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent 下的WebDriverAgent文件夹 。
b. terminer(终端工具) 在 WebDriverAgent 文件夹路径下运行:
mkdir -p Resources/WebDriverAgent.bundle
sh ./Scripts/bootstrap.sh
等待几分钟下载依赖的包后进行编译。
c. 双击WebDriverAgent.xcodeproj打开此项目,在这里我们的目的就是更改一些配置,让他能够编译成功,首先编译之前你得有 ID账号,并且登录你的Xcode账户
配置开发证书等
接着编译WebDriverAgentRunner
配置 runner 的证书信息
配置 setting 信息
d. 建立服务WebDriverAgent (手机和MAC都在同一个网段下,且都能连接外网)关闭Xcode,进入WebDriverAgent 文件夹
运行以下命令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真机的udid' test
如果终端出现以下信息,表示编译 OK,
Testing failed:
Early unexpected exit, operation never finished bootstrapping - no restart will be attempted ** TEST FAILED **
这个是时候iphone多了一个WebDriverAgentRunner的app ,
我们在通用设置的描述文件里面信任我们的开发证书之后再次运行上面的指令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真机的udid' test
如果出现以下信息,表示运行成功了:
Test Suite 'All tests' started at 2019-05-04 14:44:24.692
Test Suite 'WebDriverAgentRunner.xctest' started at 2019-05-04 14:44:24.695
Test Suite 'UITestingUITests' started at 2019-05-04 14:44:24.698
Test Case '-[UITestingUITests testRunner]' started.
t = 0.00s Start Test at 2019-05-04 14:44:24.703
t = 0.01s Set Up
2019-05-04 14:44:24.719508+0800 WebDriverAgentRunner-Runner[931:98387] Built at May 4 2019 14:43:43
2019-05-04 14:44:24.827130+0800 WebDriverAgentRunner-Runner[931:98387] ServerURLHere->http://192.168.119.105:8100<-ServerURLHer
打开终端terminer运行命令: iproxy 8100 8100 , 此时Google浏览器打开:http://localhost:8100/status
如下:
此时appium的WDA环境配置ok .
13.下载安装python3.6.8与安装常用的库,
a. 从https://www.python.org/downloads/下载python3.6.8 ,双击安装python3.6.8
b. 进入终端输入如下命令
sudo open ~/.bash_profile
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6"
修改成功的标志是,重新打开终端,输入Python,界面和python3一样
c.安装robotframework
sudo pip3 install robotframework
d.终端输入如下命令,安装wxPython 安装版本是4.03
sudo pip3 install wxPython
e. 下载和安装robotframework-ride , 地址 :https://github.com/HelioGuilherme66/RIDE/releases
sudo -H pip install -U https://github.com/HelioGuilherme66/RIDE/releases/download/v1.7.3rc1/robotframework_ride-1.7.3rc1-py2.py3-none-any.whl
f.安装常用的库
pip3 install requests
pip3 install robotframework-requests
pip3 install robotframework-selenium2library
pip3 install robotframework-seleniumlibrary
pip3 install selenium
pip3 install robotframework-appiumlibrary
g.在MAC的terminer终端运行 ride.py,如下图 ride 运行成功:
整个环境配置踩得的坑不要不要的,希望以上的环境搭建真实有效的减少大家踩坑的几率,愉快的开始自动化测试路程。
