這些都不是重點---一切均可以參考蟲師 html
1.ADB的安裝:ADB(ANDROID DEBUG BRIDGE)node
應用場景:android
針對移動端 Android 的測試, adb 命令是很重要的一個點,經常使用的 adb 命令, 將會爲 Android 測試帶來很大的方便,其
中不少命令將會用於自動化測試的腳本當中
環境搭建:
解壓:platform-tools_r28.0.0-windows.zip(adb)和sdk-tools-windows-4333796.zip (tools-UIAutomator)將解壓後的路徑放置path環境變量
命令⾏輸⼊:
adb devices:查看已鏈接的設備 adb shell wm size
adb kill-server , adb start-server , 結束 adb 服務, 啓動 adb 服務,一般兩個命令一塊兒用
adb shell pm list package:列出全部的應用的包名
-s:列出系統應用
-3:列出第三方應用
-f:列出應用包名及其安裝來源
打開應用查看包名和activity名稱:adb shell dumpsys activity top | head -n 10 mac使用命令ios
2.移動端自動化測試:APPIUMweb
環境搭建:
1.安裝node.js node-v6..zip 將解壓後的件添加至path環境變量
2.安裝appium。 將 C:\Program Files (x86)\Appium\node_modules\.bin添加至環境變量
或者 :npm install -g appium
淘寶源鏡像:npm install -g cnpm --registry=https://registry.npm.taobao.org #Windows
3.配置JAVA_HOME :就是JDK路徑
ANDROID_HOME:安卓sdk路徑
輸入:appium-doctor
All Checks were successful ,說明環境成功shell
DESIRED CAPABILITIES
Desired Capabilities在啓動session的時候是必須提供的。
本質上是key value的對象,它告訴appium server這樣一些事情:
1. ▪ 本次測試是啓動瀏覽器仍是啓動移動設備?
2. ▪ 是啓動andorid仍是啓動ios?
3. ▪ 啓動android時,app的package是什麼?
4. ▪ 啓動android時,app的activity是什麼?npm
C:\Users\ASUS-PC>adb shell
jason:/ $ dumpsys activity | grep mFocusedActivity #Windows查看package和activity----固然還有不少其餘方法(百度)windows
1.導入appium:from appium import webdriver
定義一個字典:desired_cap={
'platformName': 'Android',
'deviceName': ‘8BN0218309004925',
'appPackage': 'com.ximalaya.ting.android',
'appActivity': '.host.activity.MainActivity',
'noReset': 'true', #密碼相關,(微信爲例)註釋掉該段代碼,須要輸入登陸密碼,反正不須要登陸
'unicodeKeyboard': 'True',
'resetKeyboard': 'True',
}
而後實例化對象:driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_cap)
webdriver.Remote實際上就是原⽣webdriver的子類,第⼀個參數中須要顯⽰指定appium server監聽的端口瀏覽器
APPIUM定位元素:UIAUTOMATORVIEWER
1. 鏈接真機或模擬器
2.打開/Users/hejianhao/Library/Android/sdk/tools/bin/uiautomatorviewer
元素定位選擇器:
第⼀是ID,
第⼆是class,若是class沒有重複
第三是by uiautomator
第四,可能就是xpath 微信
APPIUM定位元素:UIAUTOMATORVIEWER1. 鏈接真機或模擬器2.打開/Users/hejianhao/Library/Android/sdk/tools/bin/uiautomatorviewerid:driver.find_element_by_accessibility_id(‘Animation’)加個s返回list:driver.find_elements_by_accessibility_id(‘Animation’)description:driver.find_element_by_android_uiautomator('new UiSelector().description(「Animation")')Xpath:://android.widget.TextView[@text=‘經典必聽’]Tag_name:driver.find_element_by_tag_name('button')