码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2020-02-01 10:22:05      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:line   android   driver   读取   sleep   aapt   open   int   表达式   

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\‘com\w*.*?\‘, 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\‘com\w*.*?\‘, appPackageAdb[i])[0]

            return appActivity

 

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

标签:line   android   driver   读取   sleep   aapt   open   int   表达式   

原文地址:https://www.cnblogs.com/chushujin/p/12247639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!