背景
公司需求:測試期間弹囚,手動測試很難測出一些崩潰的bug,一旦上線后秒啦,就能檢測到崩潰率直線上升熬粗,所以想用自動化測試來跑,在提測期間盡早盡量多的發(fā)現程序的崩潰帝蒿。
選擇Appium的原因
排前五的自動化測試中荐糜,Appium排第一巷怜,網址:https://bitbar.com/top-5-ios-testing-frameworks-with-examples/
安裝環(huán)境
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不可或缺的套件管理器
執(zhí)行下面命令:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
如圖:
5、node
有了brew安裝node就方便了
brew install node
如圖
6、npm
ajiao-macbookair:~ ajiao$ npm -v
2.0.0-alpha-5
7蹋绽、Appium
現在可以開始安裝Appium
ajiao-macbookair:~ ajiao$ appium -v
1.2.0
8瀑罗、wd
npm install wd
9、檢查環(huán)境
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的環(huán)境變量沒配置好蚪燕,那么我們要配置下娶牌。(只給ios測試的話,ANDROID_HOME不配置無所謂)
查看ios環(huán)境是否弄好了
/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
到此鲁驶,環(huán)境基本準備好了鉴裹。
最后,如果不想通過命令行安裝Appium钥弯,也可以安裝dmg
如圖:
遇到的坑:
1.發(fā)現使用命令安裝的Appium很難使用径荔。
2.推薦運行Appium app的方式,除了GUI界面操作更直觀以外寿羞,更重要的一個原因是猖凛,相比于命令行運行方式,Appium app多了一個Inspector模塊绪穆,可以調用模擬器運行被測應用程序辨泳,并且可以很方便地在預覽頁面中查看UI元素的層級結構和詳細控件屬性虱岂,極大地提高編寫測試腳本的效率。
3.下載了個Appium.dmg客戶端菠红,發(fā)現支持的版本太低了第岖,沒辦法,最后找到的解決辦法是下載appium-desktop试溯,見地址:
https://github.com/appium/appium-desktop/releases/tag/v1.2.7
下載名為:appium-desktop-1.2.7-mac.zip的壓縮文件
更多內容見下一篇Appium自動化測試之真機實踐<二>