Python+APPIUM UI自动化代码获取设备信息:devicesId、deviceName、platformVersion以及获取测试的包的package

  以下代码包含获取单个或多个设备信息,为

import os, re
import subprocess

# 项目根路径
BaseDIr = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


def get_app_devicesId():
    # 获取一个设备的devicesid
    readDeviceId = list(os.popen(‘adb devices‘).readlines())
    deviceId = re.findall(r‘^\w*\b‘, readDeviceId[1])[0]
    return deviceId


def get_app_devices():
    # 获取多个设备devicesId
    lists = os.popen(‘adb devices‘).read()
    devices = lists.strip().split(‘\n‘)
    devices_list = []
    for i in range(1, len(devices)):
        device = (devices[i].split(‘\t‘)[0])
        devices_list.append(device)
    return devices_list


def get_devices_version():
    # 获取单个系统版本号
    cmd1 = ‘adb shell getprop ro.build.version.release‘
    deviceAndroidVersion = list(os.popen(cmd1).readlines())
    deviceVersion = re.findall(r‘^\w*\b‘, deviceAndroidVersion[0])[0]
    return deviceVersion


def get_devices_info(devices_uuid):
    # 获取多设备信息
    devices_info = []
    cmd1 = ‘adb -s {} shell getprop ro.product.model‘
    cmd2 = ‘adb -s {} shell getprop ro.build.version.release‘
    if devices_uuid:
        for de in devices_uuid:
            device_model = os.popen(cmd1.format(de)).read()
            deviceos_version = os.popen(cmd2.format(de)).read()
            devices_info.append((de, device_model.strip(‘\n‘), deviceos_version.strip(‘\n‘)))
    return devices_info


# 获取测试的包的package
def get_appPackage(apkPath):
    appLocation = BaseDIr + apkPath
    if os.path.exists(appLocation):
        appPackageAdb = list(os.popen(‘aapt dump badging ‘ + appLocation).readlines())
        appPackage = re.findall(r‘\‘com\w*.*?\‘‘, appPackageAdb[0])[0]
        return appPackage




if __name__ == ‘__main__‘:
    # 打印设备信息
    devices_uuid = get_app_devices()
    print(get_devices_info(devices_uuid))

Python+APPIUM UI自动化代码获取设备信息:devicesId、deviceName、platformVersion以及获取测试的包的package

上一篇:uniapp快捷开发


下一篇:jQuery高级用法、axios、同源与跨域、JSONP以及防抖与节流