MAC电脑下Appium + python3 + robotframework ios的真机测试环境搭建

本人的环境搭建前的准备,MAC电脑一台(macOS Mojave 10.14.0及以上),Xcode 10.0及以上   ,自己注册的一个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)"

在Mac OS X 10.11系统以后,/usr/local/等系统目录下的文件读写是需要系统root权限的,以往的Homebrew安装如果没有指定安装路径,会默认安装在这些需要系统root用户读写权限的目录下,导致有些指令需要添加sudo前缀来执行,比如升级Homebrew需要:

对/usr/local 目录下的文件读写进行root用户授权: 
 sudo chown -R $USER /usr/local
 

2.安装 libimobiledevice  (得先安装Homebrew) 

brew install libimobiledevice 

其实,libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备。

 

3.安装 usbmuxd 以便于通过 USB 通道测试 iOS 真机,不需要测试真机则不用安装 

brew install usbmuxd

 

4.安装 ideviceinstaller(真机安装相关)

brew install ideviceinstaller

libimobiledevice中并不包含ipa的安装命令,所以还需要安装ideviceinstaller ,安装 ideviceinstaller 用来给真机安装 App。

 

5.安装 carthage , WebDriverAgent编译时需要的依赖包。

brew install carthage

 

6.安装 node(目的是安装 npm)官方下载地址https://nodejs.org/en/download/,下载.pkg 文件安装(LTS版本),推荐最好用Homebrew 的命令去安装 ,

brew install node

 

7.安装 iOS-deploy   

npm install -g ios-deploy

iOS-deploy 是一个终端安装和调试iPhone应用的是第三方开源库

 

8.安装 xcpretty

gem install xcpretty

xcpretty 是一个用 ruby 实现的工具,可以用 gem install xcpretty 来安装,主要作用是为了美化 xcodebuild 那冗长而且恶心的log输出

 

9. Appium 桌面端下载安装(选择 dmg 文件)下载,点击安装。

https://github.com/appium/appium-desktop/releases    

      --点击安装包

10.安装 Appium doctor 

npm install -g appium-doctor

--主要是方便用于检查MAC电脑环境是否满足Appium依赖配置

 

11 .运行命令,

Appium-doctor --ios

 --这这个命令主要是为了检查看MAC的appium ios依赖环境是否安装好。 

 

12.安装 webpack

npm i -g webpack   

 --这个鬼东西,我也不知到啥东东,呵呵

 

13.安装 wd

npm install -g wd        --(-g表示全局安装)

 --这个鬼东西,我也不知到啥东东,呵呵

 

14.应用中如含有 WebView,请安装 ios-webkit-debug-proxy

 

brew install ios-webkit-debug-proxy    --调试H5页面的用到的环境依赖 

 

15.编译并在手机安装 WebDriverAgentRunner 驱动 APP

a. 在安装完Appium Destop ,从 https://github.com/appium/WebDriverAgent 下载的WebDriverAgent文件夹 ,

b. terminer(终端工具) 在 WebDriverAgent 文件夹路径下运行:

mkdir -p Resources/WebDriverAgent.bundle

sh ./Scripts/bootstrap.sh -d

等待几分钟下载依赖的包后进行编译完。替换路径/Application/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent 下的WebDriverAgent文件夹 。

c. 双击WebDriverAgent.xcodeproj打开此项目,在这里我们的目的就是更改一些配置,让他能够编译成功,首先编译之前你得有 ID账号,并且登录你的Xcode账户

 

                                                                                                配置开发证书等

接着编译WebDriverAgentRunner

 

 

                                                                               配置 runner 的证书信息 

                                                                                配置 setting 信息   

d. 建立服务WebDriverAgent (手机和MAC都在同一个网段下,且都能连接外网)关闭Xcode,从终端terminer 进入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

 

e.打开终端terminer运行命令:

  

iproxy 8100 8100

 

如下:

 

 

f. 此时Google浏览器打开:   http://localhost:8100/status


看到这,此时appium的WDA环境配置成功了。
 
16.下载安装python3与安装常用的库,
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

pip install robotframework

 

d.终端输入如下命令,安装wxPython 安装版本是4.04

pip install wxPython==4.0.4

 

e. 下载和安装robotframework-ride  ,  地址 :https://github.com/HelioGuilherme66/RIDE/releases

    环境配置要求:

  sudo -H pip install -U -r https://github.com/HelioGuilherme66/RIDE/raw/release/requirements.txt

    ride的版本:

  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 (bug多呀)

  sudo -H pip install -U https://github.com/HelioGuilherme66/RIDE/archive/release.zip 修复了可以查看关键字帮助的bug 暂时用这个看看V1.7.3)

 

f. 安装常用的库

    pip install requests

    pip install robotframework-requests

    pip install robotframework-selenium2library

    pip install robotframework-seleniumlibrary

    pip install selenium 

    pip install robotframework-appiumlibrary

 

g. 在 MAC电脑的terminer终端运行 ride.py,如下图 ride 运行成功:

 

 

 

 整个环境配置踩得的坑不要不要的,希望以上的环境搭建介绍有效的减少大家踩坑的概率,现在可以愉快的开始自动化测试路程了,哈哈。

 The End  !

posted @ 2019-05-04 14:22  江湖萤火虫  阅读(1535)  评论(0编辑  收藏  举报