Python+appium+Android real device test example

Android

Step 1: Install the Android SDK on the computer and configure the adb command
Step 2: Open the mobile phone developer option
Step 3: Enable USB debugging in the developer option
Step 4: Execute in the terminal command lineadb devices

lujunpeng@lujunpengdeMacBook-Pro ~ % adb devices
List of devices attached
VBJDU18608004539	device

Step 5: Execute in the terminal command lineadb tcpip 5555

lujunpeng@lujunpengdeMacBook-Pro ~ % adb tcpip 5555
restarting in TCP mode port: 5555

Step 6: Open the mobile phone settings WiFi interface to find the IP of the WiFi connection
Step 7: Execute in the terminal command lineadb connect 手机IP

lujunpeng@lujunpengdeMacBook-Pro ~ % adb connect 10.10.31.85 
connected to 10.10.31.85:5555

Start appium and then use appium server to connect to the real machine
to configure parameters and get model parameter values
deviceName 设备名称​​through commandsadb devices -l

lujunpeng@lujunpengdeMacBook-Pro ~ % adb devices -l
List of devices attached
VBJDU18608004539       device usb:336592896X product:COL-AL10 model:COL_AL10 device:HWCOL transport_id:9
10.10.31.85:5555       device product:COL-AL10 model:COL_AL10 device:HWCOL transport_id:10

platformNameSystem name, Android
platformVersionsystem version, not required, view 10.0.1 through Settings-About Phone-Android Version
appPackage, application package name

Obtaining method:
1. aapt dump badging /Users/lujunpeng/Downloads/app-release.apk
2. adb shell pm list packages
3. adb shell pm list packages -3List all third-party package names
4. adb shell dumpsys window windows|grep -I current, list the package name and Activity of the currently opened application
5.adb shell dumpsys window windows | grep -E 'mCurrentFocus'

lujunpeng@lujunpengdeMacBook-Pro ~ % aapt dump badging /Users/xxx/app-release.apk
package: name='cn.xxx.management_app' versionCode='66' versionName='1.18.3' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'21'
targetSdkVersion:'28'

appActivity, the application launch item name

Obtaining method:
1. aapt dump badging /Users/lujunpeng/Downloads/app-release.apk
2.adb shell dumpsys window windows | grep -E 'mCurrentFocus'

from common import *

#前面获取的真机参数
appium_connect = {
    
    'appium:deviceName': 'COL_AL10', 'appium:appPackage': 'cn.styd.management_app',
                  'appium:appActivity': 'cn.styd.management_app.MainActivity', 'platformName': 'Android'}

driver = Remote('http://127.0.0.1:4723/wd/hub', appium_connect)
print(driver)

# 允许
driver.find_element(By.ID, 'com.android.permissioncontroller:id/permission_allow_button').click()

# 禁止
# driver.find_element(By.ID, 'com.android.permissioncontroller:id/permission_deny_button').click()

driver.find_element(By.ID, 'com.android.permissioncontroller:id/permission_allow_button').click()
time.sleep(1)
driver.find_element(By.XPATH, '//android.view.View[@content-desc="同意协议"]').click()
# driver.find_element(By.ID, 'com.android.permissioncontroller:id/permission_deny_button').click()
# driver.find_element(By.PARTIAL_LINK_TEXT, '不同意并退出').click()
driver.find_element(By.XPATH, '//android.view.View[@content-desc="登录"]').click()
driver.find_element(By.CLASS_NAME, 'android.widget.EditText').send_keys('username')
driver.find_element(By.XPATH, '//android.view.View[@content-desc="请输入密码"]').send_keys('passwrod')
driver.find_element(By.CLASS_NAME, 'android.widget.ImageView').click()
time.sleep(1)

driver.find_element(By.CLASS_NAME, 'android.view.View').click()

おすすめ

転載: blog.csdn.net/lu962820662/article/details/123531371