Appium for Mac 环境准备篇

本文详细介绍了如何在MacOS环境下为Appium自动化测试工具搭建完整的测试环境,包括安装Java、Git、Ruby、Node.js等依赖软件及配置Xcode、Android SDK等开发工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自:http://www.cnblogs.com/oscarxie/p/3894559.html

 

 

1. 爬墙
因为后续安装过程中可能会碰到墙的问题,所以首先得解决爬墙的问题。
我的方便,公司提供代理。

2. java

guowenxie-macbookair:~ guowenxie$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

3. git

guowenxie-macbookair:~ guowenxie$ git --version
git version 1.8.5.2 (Apple Git-48)

4. ruby

guowenxie-macbookair:~ guowenxie$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]

5. brew

guowenxie-macbookair:~ guowenxie$ brew -v
Homebrew 0.9.5

这边提下brew的安装,brew是Mac OS不可或缺的套件管理器
执行下面命令
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

 

 

 

6. node
有了brew安装node就方便了
brew install node

 

 

 

7. npm

guowenxie-macbookair:~ guowenxie$ npm -v
2.0.0-alpha-5

8. Appium
现在可以开始安装Appium

 

 

guowenxie-macbookair:~ guowenxie$ appium -v
1.2.0

9. wd
npm install wd

 

 

10. Xcode和Android SDK
这个不说了

11. 检查环境
Appium提供了一个doctor,运行appium-doctor

guowenxie-macbookair:~ guowenxie$ appium-doctor 
Running iOS Checks
✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer
✖ Xcode Command Line Tools are NOT installed: Error: Command failed: No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
Fix it? (y/n) y
Press any key to continue: 
✔ Xcode Command Line Tools are installed.
✔ DevToolsSecurity is enabled.
✔ The Authorization DB is set up properly.
✔ Node binary found at /usr/local/bin/node
✔ iOS Checks were successful.
Running Android Checks
✖ ANDROID_HOME is set but does not exist on the file system at "Users/guowenxie/Documents/adt-bundle_mac-x86_64-20140702/sdk"
Appium-Doctor detected problems. Please fix and rerun Appium-Doctor.

这里可以看到我Xcode Command Line Tools没有安装,这个方便,Fix it?的时候输入Y,就能自动导向安装了。
另一个是ANDROID_HOME的环境变量没配置好,那么我们要配置下。

12. bash_profile文件
Mac 默认是没有这个文件的,我们自己建一个
touch .bash_profile

vi .bash_profile
打开bash_profile文件配置ANDROID_HOME和JAVA_HOME
export ANDROID_HOME="/Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk"
export JAVA_HOME=$(/usr/libexec/java_home)

source .bash_profile
好了,再次运行appium-doctor

guowenxie-macbookair:~ guowenxie$ appium-doctor 
Running iOS Checks
✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer
✔ Xcode Command Line Tools are installed.
✔ DevToolsSecurity is enabled.
✔ The Authorization DB is set up properly.
✔ Node binary found at /usr/local/bin/node
✔ iOS Checks were successful.
Running Android Checks
✔ ANDROID_HOME is set to "/Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk"
✔ JAVA_HOME is set to "/usr/libexec/java_home."
✔ ADB exists at /Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb
✔ Android exists at /Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/android
✔ Emulator exists at /Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/emulator
✔ Android Checks were successful.
✔ All Checks were successful

到此,环境基本准备好了。

最后,如果不想通过命令行安装Appium,也可以安装dmg

 

 

 

OscarXie.net

关注质量与体验——电子商务与自动化测试
http://www.cnblogs.com/oscarxie/


### 使用AppiummacOS上的配置与应用 #### 安装必要的依赖项 为了能够在macOS上顺利运行Appium,需先确保已安装Node.js以及npm。通过Homebrew可以便捷地完成这两者的安装: ```bash brew install node ``` 这一步骤会自动安装最新版的Node.js连同npm一起[^3]。 #### 安装Appium及其相关工具 利用npm全局安装Appium服务器端软件,并且可以通过指定参数来加速国内用户的下载过程: ```bash npm install -g appium --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver ``` 对于特定版本的需求,则可采用如下方式安装: ```bash npm install -g appium@1.6.3 ``` 安装完成后,建议使用`appium-doctor`来进行环境检测以确认一切正常工作。 #### 配置Desired Capabilities 当准备启动测试时,定义合适的desired capabilities至关重要。这些设置决定了如何连接到目标设备并初始化session。具体选项可以根据实际需求调整,在官方文档中有详细的说明可供查阅[^2]。 #### 启动Appium服务 一旦上述准备工作就绪,就可以通过命令行启动Appium服务了: ```bash appium & ``` 此操作会在后台开启一个监听状态的服务实例等待客户端请求接入[^5]。 #### 编写自动化脚本 针对不同编程语言的支持情况,这里推荐Python作为入门首选之一。如果打算基于Robot Framework框架构建CI流水线的话,那么还需要额外引入`robotframework-appiumlibrary`库支持iOS/Android平台的应用交互逻辑实现[^1]。 ```python from appium import webdriver desired_caps = { 'platformName': 'Android', 'deviceName': 'emulator-5554', # 替换成自己的模拟器名称或真机序列号 } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) try: pass # 测试代码体 finally: driver.quit() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值