天天看點

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

一、環境準備

1.腳本語言:Python3.x IDE:安裝Pycharm

2.安裝Java JDK 、Android SDK

3.adb環境,path添加E:\Software\Android_SDK\platform-tools

4.安裝Appium for windows,官網位址http://appium.io/

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

點選下載下傳按鈕會到GitHub的下載下傳頁面,選擇對應平台下載下傳

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

安裝完成後,啟動Appium,host和port預設的即可,然後設定Android SDk和Java JDK

python自動化測試流程_Python+Appium實作自動化測試的使用步驟
python自動化測試流程_Python+Appium實作自動化測試的使用步驟

然後點下邊那個儲存并重新開機的按鈕,然後點第一個Start Server按鈕,将會看到

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

二、真機測試

1.連接配接手機

打開開發者模式,USB線連接配接手機和電腦,并且在開發者選項當中,開啟USB調試

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

測試是否連接配接成功,可執行指令adb devices

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

出現上圖就證明手機和電腦連接配接成功。。。

2.點選Start Inspector Session,

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

按如下配置Desired Capabilities

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

platformName:聲明是ios還是Android系統

platformVersion: Android核心版本号,可通過指令adb shell getprop ro.build.version.release檢視

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

deviceName:連接配接的裝置名稱,通過指令adb devices -l中model檢視

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

appPackage:apk的包名

appActivity:apk的launcherActivity,通過指令adb shell dumpsys activity | findstr “mResume”檢視(需先打開手機應用)

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

注意:Android 8.1之前應使用adb shell dumpsys activity | findstr “mFocus”

3.運作Start Session,選擇元素

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

右側 Selected Element 區域有三個按鈕

Tap:執行選中元素的點選事件Send Keys:為文本框等對象傳值如果是文本輸入元素,就清除文本

4.錄制腳本

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

錄制生成的python代碼如下:

# This sample code uses the Appium python client

# pip install Appium-Python-Client

# Then you can paste this into a file and simply run with Python

from appium import webdriver

caps = {}

caps["platformName"] = "Android"

caps["platformVersion"] = "9.0.0"

caps["deviceName"] = "Mi_Note_3"

caps["appPackage"] = "com.antfortune.wealth"

caps["appActivity"] = "com.alipay.mobile.quinox.LauncherActivity"

caps["resetKeyboard"] = True

caps["unicodeKeyboard"] = True

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

el1 = driver.find_element_by_id("com.antfortune.wealth.login:id/login_main_button")

el1.click()

el2 = driver.find_element_by_id("com.alipay.mobile.accountauthbiz:id/auth_login_btn")

el2.click()

driver.quit()

5.在pycharm中建立項目将代碼粘入,在運作之前,還需通過pip指令安裝pip install Appium-Python-Client依賴包

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

最後,記一個我在這些過程中遇到的問題(現已解決)

在Appium-desktop中運作Start Session時,出現

python自動化測試流程_Python+Appium實作自動化測試的使用步驟

解決方法:在開發者模式下,打開usb調試功能和use模拟點選,兩個都要打開,此時再重新運作,即可解決

到此這篇關于Python+Appium實作自動化測試的使用步驟的文章就介紹到這了,更多相關Python Appium 自動化測試 内容請搜尋腳本之家以前的文章或繼續浏覽下面的相關文章希望大家以後多多支援腳本之家!