appium 学习笔记(二)

自动获取platformVersion、deviceName、appPackage、appActivity:

在本地目录下新建adbbase.py:

import re
import os

appLocation = "E:\\test\kxlp5_v1.5.5.apk"

def platformName():
    readDeviceName = list(os.popen('adb devices').readlines())
    deviceName = re.findall(r'^\w*\b',readDeviceName[1])[0]
    return deviceName

def platformVersion():
    deviceAndroidVersion = list(os.popen('adb shell getprop ro.build.version.release').readlines())
    deviceVersion = re.findall(r'^\w*\b',deviceAndroidVersion[0])[0]
    return deviceVersion

def appPackage():
    appPackageAdb = list(os.popen('chcp 65001 | aapt dump badging '+appLocation+'  | findstr package').readlines())
    appPackage = re.findall(r"name='(.+?)' versionCode",appPackageAdb[0])[0]
    return appPackage

def appActivity():
    appActivityAdb = list(os.popen('chcp 65001 | aapt dump badging '+appLocation+'  | findstr launchable-activity').readlines())
    appActivity = re.findall(r"name='(.+?)'  label",appActivityAdb[0])[0]
    return appActivity


在原来的自动化代码里添加

import adbbase

修改

desired_caps = {}
desired_caps['PlatformName'] = 'Android'
desired_caps['PlatformVersion] = '6.0'
desired_caps['deviceName'] = 'huawei'
desired_caps['appPackage'] = 'com.happy.food'
desired_caps['appActivity'] = 'com.happy.activity.LauncherActivity'

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['paltformVersion'] = adbbase.platformVersion()
desired_caps['deviceName'] = adbbase.platformName()
desired_caps['appPackage'] = adbbase.appPackage()
desired_caps['appActivity'] = adbbase.appActivity()

阅读更多
文章标签: appium
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭