APP——自动化——python——调用、判断、安装、启动第三方app

owilson 2020-06-26

# 计算器:     C:\Users\del>adb shell dumpsys window w |findstr \/ |findstr name=
#              mSurface=Surface(name=com.youba.calculate/com.youba.calculate.MainActivity)            #adb命令查看包名和启动activity

#com.youba.calculate:id/btn_plus  +
#com.youba.calculate:id/btn_equal  =


#凤凰网:   C:\Users\del>adb shell dumpsys window w |findstr \/ |findstr name=
#           mSurface=Surface(name=com.ifext.news/com.ifeng.news2.activity.IfengTabMainActivity)


#baidu :C:\Users\del>adb shell dumpsys window w |findstr \/ |findstr name=
#      mSurface=Surface(name=com.baidu.searchbox/com.baidu.searchbox.MainActivity)

from appium import webdriver
import  time

desired_caps = {
    ‘platformName‘: ‘Android‘,             #待测试手机的系统
    ‘deviceName‘:‘8DF6R17503000072‘,     #使用手机或模拟器的类型
    ‘platformVersion‘: ‘8.0.0‘,                         #待测手机系统版本
     "unicodeKeyboard":"true",   #支持中文输入,会自动安装unicode输入法,默认是false
     "resetKeyboard":"true",    #如果设置了中文输入为true,此设置为自动化退出后,重置输入法到原来状态
    "autoGrantPermissions":"true",   #获取所有权限
    #‘app‘: ‘C:\\Users\\del\\Desktop\\b\\jsq.apk‘,         #手机未按照待测app时,设置安装路径、包名、启动activity
    ‘appPackage‘: ‘com.youba.calculate‘,
    ‘appActivity‘: ‘com.youba.calculate.MainActivity‘,
}


driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)

time.sleep(5)

driver.press_keycode(3)

time.sleep(5)

driver.start_activity(‘com.baidu.searchbox‘,‘com.baidu.searchbox.MainActivity‘)           #打开第三方app

time.sleep(5)

driver.press_keycode(3)           #HOME键

time.sleep(5)

driver.launch_app()        #  启动初始化app

time.sleep(5)

driver.close_app()             #关闭初始化的app

time.sleep(5)

print(‘----------------------------------------------------------------------‘)

print(driver.is_app_installed("com.ifext.news"));         #判断第三方app是否安装         返回了:true

time.sleep(10)

driver.remove_app("com.ifext.news")             #删除(卸载)第三方app

time.sleep(10)


driver.install_app(‘?C:\\Users\\del\\Desktop\\b\\ifeng.apk‘)


time.sleep(10)


driver.start_activity(‘com.ifext.news‘,‘com.ifeng.news2.activity.IfengTabMainActivity‘)

driver.quit()

相关推荐