Appium之mac OS 10.12.5+Xcode 8.3.2 配置使用

来源:互联网 发布:java软件开发招聘信息 编辑:程序博客网 时间:2024/05/16 10:09

1、下载或者更新Homebrew:

       homebrew官网 macOS 不可或缺的套件管理器

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"  #下载$ brew update #更新$ brew -vHomebrew 1.1.5Homebrew/homebrew-core (git revision e151b; last commit 2016-12-26)

2、使用homebrew来安装node.js

       Node.js教程

       node采用C++编写,是一个JavaScript的运行环境,因为JS是脚本语言需要一个解析器才能运行,对于写在HTML页面的JS,浏览器本身就是解析器,对于需要单独运行的JS,Node.js就是解析器。

$ brew install node$ node -vv7.3.0

3、安装npm:

       NPM 使用介绍 是一个NodeJS包管理和分发工具,已经成为了非官方的发布Node模块(包)的标准。

$ brew install npm

4、使用npm来安装appium

       2017.01.03目前最新的版本是 1.6.3 ,当然也可以在 macOS下bitbucket下载appium客户端,但是坑人的是最新版本是 1.5.3 支持的还只是 iOS10 以下的 UIAutomation 框架基础上测试,而 iOS10 以后苹果使用的却是基于 XCUITest ,所以只能采用npm安装咯。但是因为国内墙太高而使用npm却是从国外服务器下载,有时候使用npm需要非常长的时间,更多时候是失败,推荐使用cnpm来安装:

       淘宝 NPM 镜像 10分钟同步npmjs.org镜像,使用方式和npm完全一致

$ npm install cnpm -g --registry=https://registry.npm.taobao.org$ npm view appium versions #查看appium所有的版本号

5、使用cnpm安装appium和appium-doctor

$ cnpm install -g appium --no-cache$ cnpm install -g appium$ cnpm install -g appium-doctor

6、检查appium环境检测:

$ appium-doctorinfo AppiumDoctor Appium Doctor v.1.4.2info AppiumDoctor ### Diagnostic starting ###info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/DeveloperWARN AppiumDoctor  ✖ Xcode Command Line Tools are NOT installed!info AppiumDoctor  ✔ DevToolsSecurity is enabled.info AppiumDoctor  ✔ The Authorization DB is set up properly.info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/nodeinfo AppiumDoctor  ✔ Carthage was found at: /usr/local/bin/carthageinfo AppiumDoctor  ✔ HOME is set to: /Users/denglibingWARN AppiumDoctor  ✖ ANDROID_HOME is NOT set!info AppiumDoctor  ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/HomeWARN AppiumDoctor  ✖ adb could not be found because ANDROID_HOME is NOT set!WARN AppiumDoctor  ✖ android could not be found because ANDROID_HOME is NOT set!WARN AppiumDoctor  ✖ emulator could not be found because ANDROID_HOME is NOT set!WARN AppiumDoctor  ✖ Bin directory for $JAVA_HOME is not setinfo AppiumDoctor ### Diagnostic completed, 6 fixes needed. ###info AppiumDoctor info AppiumDoctor ### Manual Fixes Needed ###info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:WARN AppiumDoctor - Manually configure ANDROID_HOME.WARN AppiumDoctor - Manually configure ANDROID_HOME and run appium-doctor again.WARN AppiumDoctor - Add '$JAVA_HOME/bin' to your PATH environmentinfo AppiumDoctor ###info AppiumDoctor info AppiumDoctor Bye, run appium-doctor again when all manual fixes have been applied!info AppiumDoctor 

常见问题解决:

(1)、Xcode Command Line Tools are NOT installed!

$ xcode-select --install  

       按照提示安装即可

(2)、Carthage was NOT found!

$ brew install carthage      

carthage:类似cocoapods管理第三方代码,自动将工程编译为动态库,所以仅支持iOS8以上

(3)、WARN AppiumDoctor ✖ ANDROID_HOME is NOT set!

       建议安装Android编译器,可以解决其他Android环境的其他问题

       AndroidStudio(https://developer.android.com/studio/index.html?hl=zh-cn)

       设置 ANDROID_HOME 路径:

       http://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x

       设置 JAVA_HOME 路径:

       http://stackoverflow.com/questions/6588390/where-is-java-home-on-osx-sierra-10-12-el-captain-10-11-yosemite-10-10

(4)、JAVA_HOME问题:

       当前最新JDK版本下载地址 Java SE Development Kit 8u111 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

       .bash_profile文件:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Homeexport ANDROID_HOME=/Users/yourname/Library/Android/sdkexport PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:${JAVA_HOME}/bin

7、安装appium客户端

       上面的操作只是安装了server端,接下来需要安装测试代码运行所依赖的客户端,我们以python为例:

git clone https://github.com/appium/python-clientcd python-client-master sudo python setup.py install

8、安装 appium-xcuitest-driver

       对于 iOS10 以上的测试,需要下载安装 appium-xcuitest-driver 驱动:Appium iOS driver, backed by Apple XCUITest

       或者重新安装 appium-xcuitest-driver (先卸载在重新安装新版本2.5.3)

       原因:appium 默认安装的appium-xcuitest-driver版本有点老,貌似是 2.4.0的版本,老的版本问题,运行测试的时候会提示

[debug] [WebDriverAgent] Device: Mar 29 15:29:21 Cheersde-iPhone XCTRunner[2848] <Notice>: Running tests...[debug][WebDriverAgent] Device: Mar 29 15:29:22 Cheersde-iPhone XCTRunner[2848] <Notice>: Continuing to run tests in the background with task ID 1[debug] [XCUITest] Waiting for WebDriverAgent server to finish loading...

       导致被测试的app launch不起来,一直卡在 [debug][XCUITest] Waiting for WebDriverAgent server to finish loading... 这块

       而新的版本appium-xcuitest-driver 2.5.3 就解决了这个问题。

安装方法:

cd /usr/local/lib/node_modules/appium   npm uninstall appium-xcuitest-driver         先卸载npm install appium-xcuitest-driver@2.5.3  重新安装 2.5.3

       当然也可以在 /usr/local/lib/node_modules/appium/node_modules/.2.5.1@appium-xcuitest-driver/WebDriverAgent/ 找到该项目,执行 carthage update , 选择 WebDriverAgentRunner 编译即可。

       但是这种方法很不方便,下面提供一种更简单的的:

安装appium-xcuitest-driver依赖

       进入WebDriverAgent安装目录。运行bootstrap
cd /usr/local/lib/node_modules/appium/node_modules/_appium-xcuitest-driver@2.35.0@appium-xcuitest-driver/WebDriverAgent (如果WebDriverAgent 所在路径和此不同,请自行查找)

mkdir -p Resources/WebDriverAgent.bundlesh ./Scripts/bootstrap.sh -d

       在运行sh ./Scripts/bootstrap.sh -d很可能会有因为某种原因而网络连接失败。方法就是去下载了一个VPN代理软件,我下的是云梯VPN,使用这个链接,我们都能优惠10元。

       再次运行sh ./Scripts/bootstrap.sh -d 无报错就OK了

其他相关的安装

$ brew install libimobiledevice --HEAD  # install from HEAD to get important updates$ brew install ideviceinstaller         # 只是对iOS9有用$ npm install -g ios-deploy                # iOS10 以后的版本安装ios-deploy$ sudo gem install xcpretty            # 真机需要安装 xcpretty

9、下载测试代码并且测试

       官网上的测试代码坑很多,这个问题我困扰我好久。一开始还以为是自己那个环境出问题还是流程不对,结果真的只是官网测试代码本身问题,当然可以自己编写代码测试咯,也可以下载我找的一个简单的 appium_ios_sample_code

       先执行模拟器的测试

$ cd sample-code/apps/HHH#在sample-code/apps/HHH/build/Release-iphonesimulator/得到HHH.app包$ xcodebuild -sdk iphonesimulatorBuild settings from command line:    SDKROOT = iphonesimulator10.2=== BUILD TARGET HHH OF PROJECT HHH WITH THE DEFAULT CONFIGURATION (Release) ===.........Signing Identity:     "-"    /usr/bin/codesign --force --sign - --timestamp=none /Users/denglibing/Desktop/sample-code/apps/HHH/build/Release-iphonesimulator/HHH.app** BUILD SUCCEEDED **$ cd sample-code/examples/python$ python ios_simple_simulator.pytest_scroll (__main__.SimpleIOSTests) ... ok----------------------------------------------------------------------Ran 1 test in 30.421sOK

       对于真机,可能要麻烦些,安装 appium-xcuitest-driver 驱动后,生成在真机上运行的包:

       参考资料可以看官网的说明 部署ios-app到手机上

# 在 apps/HHH/build/Release-iphoneos/HHH.app 得到 release 包$ xcodebuild -sdk iphoneos -target HHH -configuration Release CODE_SIGN_IDENTITY="iPhone Distribution: Shenzhen XXXX Technology Co., Ltd. (B9FH944VTE)" PROVISIONING_PROFILE="08f04032-ca2e-4bb5-b1ba-c32778115f2e"

       关于怎么设置 CODE_SIGN_IDENTITYPROVISIONING_PROFILE 如何查看 ,可以选择下图所示的 Development Team 一行, control+c 然后 复制出去即可

       接下来连上真机 执行测试用例代码:

$ cd sample-code/examples/python$ python ios_simple_device.pytest_scroll (__main__.SimpleIOSTests) ... ok----------------------------------------------------------------------Ran 1 test in 30.421sOK

10:一些很有帮助的资料

       自动化测试必去论坛 https://testerhome.com

       appium源码地址: https://github.com/appium/appium

       appium官网地址:http://appium.io/

       appium中文说明文档:http://appium.io/slate/cn/master/?ruby#about-appium

       appium国内安装包:https://pan.baidu.com/s/1jGvAISu#list/path=%2F&parentPath=%2F

       macOS10.12配置appium

       Appium 1.6.3 在Xcode 8 (真机)测试环境搭建 经验总结

       appium-desktop-1.0.0.dmg appium 1.6.4 (真机)问题和解决方法

       Appium 在 MAC 上搭建 appium1.6.3 过程

       mac appium ios python 之首次运行测试用例

        appium的几点总结(主要关于如何用java完成appium的测试的一些API)

        (六) appium 1.6 使用与APP-inspector定位

        appium-desktop下载

11、心得:

       整体的流程其实不多,但是在macOS10.12搭建appium的环境及测试整个过程着实烦躁,有时候一个小问题就卡1-2天也不好说,而且官网上的文档和测试代码已经部分误导我走了非常多的歪路。

原创粉丝点击