記一個Android菜雞的走偏之路。谆奥。
前些日子給組里QA姐姐們探了探Appium這個自動化測試框架在一些平臺上的使用祖凫,網(wǎng)上的資料都比較零散,就自己嘗試歸納總結(jié)了一下搭建環(huán)境的步驟
之前未曾裝過Appium的相關(guān)環(huán)境的話违施,按以下步驟一路走完的話應(yīng)該就可以跑起來了。瑟幕。
都是一些簡單的操作磕蒲,視實(shí)際按需取用吧
emmm僅對我本地Mac OS 10.12.6 + python 2.7.10版本負(fù)責(zé)(:з」∠)
環(huán)境搭建
0.安裝Xcode Command Line Tools
(app store安裝Xcode后)
terminal下輸入
xcode-select --install
1.安裝brew
terminal下輸入
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.git
terminal下輸入
brew install git
3.使用brew安裝node和npm
terminal下輸入
brew install node
安裝完輸入 npm -v
來測試是否成功安裝
4.安裝java
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下載Java SE Development Kit 8
選擇jdk-xxxxx-macosx-x64.dmg下載并安裝
5.安裝Android Developer Tools
https://developer.android.com/index.html
獲取android studio并安裝運(yùn)行一次
6.添加java&ADB環(huán)境變量
terminal下輸入
vim ~/.bash_profile
按i進(jìn)入Insert模式
在最后添加:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
#此處“jdk1.8.0_xxx.jdk”為實(shí)際安裝的java版本
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
按ESC輸入:wq
回車保存退出
terminal下輸入java -v
查看java版本是否正確,輸入adb
查看ADB是否配置正確
7.命令行安裝appium
terminal下輸入
npm install -g appium
npm install -g appium-doctor
npm install wd
由于安裝需要連接國外的技術(shù)站點(diǎn)只盹,國內(nèi)網(wǎng)絡(luò)不穩(wěn)定導(dǎo)致安裝失敗辣往。大家可嘗試使用淘寶鏡像,在~目錄創(chuàng)建文件.npmrc殖卑,然后加入一行
chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver
8.為python安裝pip
8.1 Install easy_install
curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
8.2 Install pip
sudo easy_install pip
9.安裝Appium for python客戶端
pip install Appium-Python-Client --user
10.使用appium-doctor檢查安裝
terminal下輸入
appium-doctor
輸出如
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.1.4
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.
WARN AppiumDoctor ? Carthage was NOT found!
info AppiumDoctor ? HOME is set to: /Users/t_chenju
info AppiumDoctor ? ANDROID_HOME is set to: /Users/t_chenju/Library/Android/sdk
info AppiumDoctor ? JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
info AppiumDoctor ? adb exists at: /Users/t_chenju/Library/Android/sdk/platform-tools/adb
info AppiumDoctor ? android exists at: /Users/t_chenju/Library/Android/sdk/tools/android
info AppiumDoctor ? emulator exists at: /Users/t_chenju/Library/Android/sdk/tools/emulator
WARN AppiumDoctor ? Bin directory for $JAVA_HOME is not set
info AppiumDoctor ### Diagnostic completed, 2 fixes needed. ###
info AppiumDoctor
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor - Please install Carthage. Visit https://github.com/Carthage/Carthage#installing-carthage for more information.
WARN AppiumDoctor - Add '$JAVA_HOME/bin' to your PATH environment
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor
檢查WARN項(xiàng)
至此站削,本地的appium腳本測試環(huán)境就搭建好了
可按照下方 -在MQC中使用Appium進(jìn)行腳本測試- 鏈接里的內(nèi)容進(jìn)行腳本開發(fā)對環(huán)境進(jìn)行驗(yàn)證
appium reference<中文>
http://appium.io/slate/cn/master/?python
在MQC中使用Appium進(jìn)行腳本測試
http://mqc.aliyun.com/doc.htm?id=17
在AWS-Device Farm中使用appium進(jìn)行腳本測試
與MQC僅支持一個main.py作為testsuite,并且使用unittest作為用例測試工具不同的是孵稽,AWS-Device Farm所提供的測試基礎(chǔ)環(huán)境是可移植并可按實(shí)際需求添加第三方拓展包的许起。我們需要在本地建立workspace文件夾,將此文件夾作為一個python的虛擬環(huán)境與本地開發(fā)環(huán)境隔離開來(沙盒)菩鲜。在AWS上進(jìn)行腳本測試時將此環(huán)境中的所必需的測試腳本文件园细、第三方拓展一并打包上傳即可。
- 若已在上步“在MQC中使用Appium進(jìn)行腳本測試”編寫好可以運(yùn)行的腳本文件接校,可以將其 main.py 與 desired_capabilities.py一同拷貝至下面的“tests”文件夾即可猛频。
安裝虛擬環(huán)境工具
- terminal下輸入
sudo easy_install virtualenv
- 按以下鏈接中 “Build the Appium Python Test Package” 標(biāo)簽下的步驟進(jìn)行構(gòu)建環(huán)境
https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-appium-python.html- 注意:由于virtualenv,此文件夾與本地python環(huán)境隔離蛛勉,在以上網(wǎng)頁 <b>step4</b> "Make sure you have py.test installed in your virtual environment and test cases are discoverable by the following command, which you should run from your virtual environment workspace folder." <b>之前</b>鹿寻,將編寫好的腳本文件拷貝至tests文件夾,并在此環(huán)境中安裝你需要的第三方包及Appium-Client董习。例如:
pip install Appium_Python_Client
- 注意:由于virtualenv,此文件夾與本地python環(huán)境隔離蛛勉,在以上網(wǎng)頁 <b>step4</b> "Make sure you have py.test installed in your virtual environment and test cases are discoverable by the following command, which you should run from your virtual environment workspace folder." <b>之前</b>鹿寻,將編寫好的腳本文件拷貝至tests文件夾,并在此環(huán)境中安裝你需要的第三方包及Appium-Client董习。例如:
- 按照以上網(wǎng)頁的步驟得到的 .zip 文件即為符合要求的AWS測試腳本集文件烈和。
進(jìn)一步的測試范例,可參考
https://github.com/appium/sample-code/tree/master/sample-code/examples
常用的一些api
查找當(dāng)前l(fā)ayout控件元素
1. driver.find_element_by_id()
2. driver.find_element_by_name() (iOS可用)
3. driver.find_element_by_accessibility_id()
4. driver.find_element_by_classname()
5. driver.find_element_by_xpath()