Android 测试iOS精选ios 自己

MAC下搭建 appium+ios+python 自动化测试环境

2018-05-24  本文已影响230人  红发_KVO

Mac 下 appium +python 自动化测试系列:
Mac 下搭建 appium+ios+python 自动化测试环境(一)
Mac 下 appium 自动化测试iOS 测试配置和脚本编写(二)
Mac 下 搭建appium +android+python 自动化测试环境(三)
Mac 下 appium 自动化测试 Android 测试配置和脚本编写(四)

环境搭建要求,MAC 机器一台,要求 Xcode 8.0以上,有 Apple ID 账号,懂一点点终端命令,最重要的是能够联网,如果都 OK 了,那就可以开搞了!

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install libimobiledevice
brew install  ideviceinstaller
brew install carthage

安装 carthage容易出现以下错误

Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

原因是carthage已经安装,但是没有 link 到 brew,还有就是文件夹权限问题,在终端输入:

sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
brew link carthage
This package has installed:
    •   Node.js v8.11.2 to /usr/local/bin/node
    •   npm v5.6.0 to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
npm install -g cnpm --registry=https://registry.npm.taobao.org

安装这个坑比较多,一般会出现以下提示:

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

这个时候你换成

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

如果脸不好,或者网络问题,又会出现以下问题:

npm WARN registry Unexpected warning for https://registry.npm.taobao.org/: Miscellaneous Warning ETIMEDOUT: request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 114.55.80.225:443
npm WARN registry Using stale package data from https://registry.npm.taobao.org/ due to a request error during revalidation.

网上找一了一圈,还是没解决,最后还是根据权限提示,自己摸索出来的,先打开目录权限,然后再安装镜像

sudo chown $(whoami):admin /usr/local/lib/node_modules/

npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g ios-deploy

这个会出现超时错误

Get /binary-mirror-config/latest from https://registry.npm.taobao.org error: ConnectionTimeoutError: Connect timeout for 5000ms, GET https://registry.npmjs.org/binary-mirror-config/latest -2 

感觉就是淘宝的镜像源的问题,没有同步或者什么原因,解决方法如下:

//设置镜像源
npm config set registry https://registry.npm.taobao.org --global
//配置镜像列表
npm config list
//执行安装指令
npm install -g ios-deploy
gem install xcpretty

如果没使用代理或者公司网有限制的话,一般没问题。

npm install -g appium

安装完顺便安装 appium doctor

npm install -g appium-doctor

公司网络太坑,我用的手机热点下的,妈蛋啊,心疼我的流量!

接着安装 python 的环境

git clone git@github.com:appium/python-client.git
cd python-client
python setup.py install
npm install -g wd
npm i -g webpack 
#如果已经安装,请先卸载
#npm uninstall appium-xcuitest-driver
npm install appium-xcuitest-driver

首先,我想说这个 appium 自带的项目,有毒啊!!这个真的有毒啊,绝对有毒啊!

cd  /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

mkdir -p Resources/WebDriverAgent.bundle

sh ./Scripts/bootstrap.sh

运行完,就是报fatal: could not read Username for 'https://github.com': terminal prompts disabled这个错误啊,原因竟然是,依赖库里面的 Cartfile里面的依赖库不见了啊!我搞了一天多,搜索都搜索的要吐了!

正确姿势如下,请 get✔️
先进到用户目录下或者根目录下:

cd ~

git clone https://github.com/facebook/WebDriverAgent.git

cd WebDriverAgent

mkdir -p Resources/WebDriverAgent.bundle

sh ./Scripts/bootstrap.sh

一顿操作猛如虎之后, 进入到appium-xcuitest-driver路径下

cd  /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/

rm –rf WebDriverAgent(移除自带的,当然如果没有安装自带的就不用执行这个指令)

ln -s ~/WebDriverAgent WebDriverAgent  (其中~/WebDriverAgent是源地址,后面的是目标地址,也就是把你 clone 的项目链接到 driver 里面)

1.进入目标文件或者你刚链接的源文件也行(链接之后源文件改变,引用文件也会改变)


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


    配置开发证书等

    接着编译WebDriverAgentRunner


    配置 runner 的证书信息
    配置 setting 信息
cd  /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/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

如果出现以下信息,表示运行成功了:

2018-04-26 16:25:33.445429+0800 WebDriverAgentRunner-Runner[314:21633] Continuing to run tests in the background with task ID 1
Test Suite 'All tests' started at 2018-04-26 16:25:33.508
Test Suite 'WebDriverAgentRunner.xctest' started at 2018-04-26 16:25:33.509
Test Suite 'UITestingUITests' started at 2018-04-26 16:25:33.510
Test Case '-[UITestingUITests testRunner]' started.
    t =     0.01s Start Test at 2018-04-26 16:25:33.518
    t =     0.01s Set Up
2018-04-26 16:25:33.527655+0800 WebDriverAgentRunner-Runner[314:21633] Built at May 22 2018 07:53:09
2018-04-26 16:25:33.552834+0800 WebDriverAgentRunner-Runner[314:21633] ServerURLHere->http://172.20.10.7:8100<-ServerURLHere

这个时候我们来一遍验证吧。

appium-doctor --ios

出现如下信息:

info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ Node version is 8.11.2
info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ Xcode Command Line Tools are installed.
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
info AppiumDoctor  ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor  ✔ HOME is set to: /Users/xxxxxx
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor 

至此,说明我们环境配置成功了!

整个环境配置踩得的坑不要不要的,主要是公司是内网,上外网用的代理,也没法挂 VPN,希望以上的环境搭建真实有效的减少你们踩坑的几率,愉快的开始自动化测试路程!下一篇,我会写一下如何进行脚本测试和 appium desktop 的使用!

参考:

在 MAC 上搭建 appium1.6.3 过程

Xcode9.0+appium1.6.5真机环境运行app及遇坑知多少

appium mac 下 安装及踩坑

上一篇下一篇

猜你喜欢

热点阅读