五、Appium-python-UI自动化之自动获取devicesd,version,package,appActivi

时间:2022-02-27 18:00:54

from appium import webdriver

# 使用正则表达式筛选设备 id
import re

# 使用time.sleep(xx)函数进行等待
import time

# 使用 os 模块调用命令
import os

def get_sales_package():

    # 测试的销售APP包的路径和包名
    sales_appLocation = os.path.split(os.path.dirname(__file__))[0]   "/app_package/sales_app_product.apk"

    return sales_appLocation
def get_dragon_package():

    # 测试的客户APP包的路径和包名
    dragon_appLocation = os.path.split(os.path.dirname(__file__))[0]   "/app_package/dragon_app_product.apk"

    return dragon_appLocation

def get_app_devices_id():

    # 读取设备 id
    readDeviceId = list(os.popen(adb devices).readlines())

    # 正则表达式匹配出 id 信息
    deviceId = re.findall(r^w*b, readDeviceId[1])[0]

    return deviceId

def get_app_device_version():

    # 读取设备系统版本号
    deviceAndroidVersion = list(os.popen(adb shell getprop ro.build.version.release).readlines())

    deviceVersion = re.findall(r^w*b, deviceAndroidVersion[0])[0]

    return deviceVersion

def get_app_app_package_info(app):

    if app == "sales":

        app_location = get_sales_package()

    elif app == "dragon":

        app_location = get_dragon_package()

    # 读取 APK 的 package 信息
    appPackageAdb = list(os.popen(aapt dump badging    app_location).readlines())

    for i in range(len(appPackageAdb)):

        # print(str(i) ":" str(appPackageAdb[i]))

        if "package" in appPackageAdb[i]:

            appPackage = re.findall(r‘comw*.*?‘, appPackageAdb[i])[0]

            return appPackage

def get_app_app_activity_info(app):

    if app == "sales":

        app_location = get_sales_package()


        app_location = get_sales_package()

    # 读取 APK 的 package 信息
    appPackageAdb = list(os.popen(aapt dump badging    app_location).readlines())

    for i in range(len(appPackageAdb)):

        # print(str(i) ":" str(appPackageAdb[i]))

        if "launchable-activity" in appPackageAdb[i]:

            appActivity = re.findall(r‘comw*.*?‘, appPackageAdb[i])[0]

            return appActivity