Appium自动化测试之环境搭建<一>

背景

公司需求:测试期间,手动测试很难测出一些崩溃的bug,一旦上线后,就能检测到崩溃率直线上升,所以想用自动化测试来跑,在提测期间尽早尽量多的发现程序的崩溃。

选择Appium的原因

排前五的自动化测试中,Appium排第一,网址:https://bitbar.com/top-5-ios-testing-frameworks-with-examples/

安装环境

1、java

ajiao-macbookair:~ ajiao$ 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)

2、git

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

3、ruby

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

4、brew

ajiao-macbookair:~ ajiao$ brew -v
Homebrew 0.9.5
这边提下brew的安装,brew是Mac OS不可或缺的套件管理器
执行下面命令:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
如图:

brew

5、node

有了brew安装node就方便了
brew install node
如图


node

6、npm

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

7、Appium

现在可以开始安装Appium

Appium

ajiao-macbookair:~ ajiao$ appium -v
1.2.0

8、wd

npm install wd

wd

9、检查环境

Appium提供了一个doctor,运行appium-doctor
ajiao-macbookair:~ ajiao$ 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/ajiao/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的环境变量没配置好,那么我们要配置下。(只给ios测试的话,ANDROID_HOME不配置无所谓)

查看ios环境是否弄好了
/usr/local/bin/appium-doctor [options, defaults: --ios ]

10、bash_profile文件

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

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

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

ajiao-macbookair:~ ajiao$ 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/ajiao/Documents/adt-bundle-mac-x86_64-20140702/sdk"
✔ JAVA_HOME is set to "/usr/libexec/java_home."
✔ ADB exists at /Users/ajiao/Documents/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb
✔ Android exists at /Users/ajiao/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/android
✔ Emulator exists at /Users/ajiao/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/emulator
✔ Android Checks were successful.
✔ All Checks were successful
到此,环境基本准备好了。
最后,如果不想通过命令行安装Appium,也可以安装dmg

如图:


wd

遇到的坑:
1.发现使用命令安装的Appium很难使用。
2.推荐运行Appium app的方式,除了GUI界面操作更直观以外,更重要的一个原因是,相比于命令行运行方式,Appium app多了一个Inspector模块,可以调用模拟器运行被测应用程序,并且可以很方便地在预览页面中查看UI元素的层级结构和详细控件属性,极大地提高编写测试脚本的效率。
3.下载了个Appium.dmg客户端,发现支持的版本太低了,没办法,最后找到的解决办法是下载appium-desktop,见地址:
https://github.com/appium/appium-desktop/releases/tag/v1.2.7
下载名为:appium-desktop-1.2.7-mac.zip的压缩文件

更多内容见下一篇Appium自动化测试之真机实践<二>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。