首页 > 移动平台 > 详细

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

时间:2021-01-11 14:46:12      阅读:155      评论:0      收藏:0      [点我收藏+]

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

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

原文:https://www.cnblogs.com/dy99/p/14261401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!