appium移动自动化对应用的操作

1. 使用Python + Appium实现apk的安装

2. 使用Python + Appium实现apk的卸载

3. 使用Python + Appium实现apk的关闭或启动等其它操作


#安装apk
from appium import webdriver

#启动信息
desired_caps = { }
#设备参数
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '23'
desired_caps['deviceName'] = 'Android Emulator'

#测试apk包的路径
apk_path = r'D:\App6.0.12_stRelease_test.apk'
desired_caps['app'] = apk_path

driver =webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
#安装apk
driver.install_app(apk_path)

#判断apk是否安装成功,结果为True/False
is_installed = driver.is_app_installed('com.puscene.client') #这是要安装的apk的包名:com.puscene.client
if is_installed:
print('安装成功。')
else:
print('安装失败。')

driver.quit()

#卸载apk
from appium import webdriver

#启动信息
desired_caps = {}
#设备参数
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '23'
desired_caps['deviceName'] = 'Android Emulator'
# com.tencent.mm/.plugin.account.ui.WelcomeActivity
desired_caps['appPackage'] = 'com.tencent.mm' #微信的包
desired_caps['appActivity'] = '.plugin.account.ui.WelcomeActivity'

driver =webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
#判断 apk是否安装,结果为 True /False
is_installed = driver.is_app_installed('com.tencent.mm')
print(is_installed)
driver.remove_app('com.tencent.mm')
is_installed =driver.is_app_installed('com.tencent.mm')
print(is_installed)

driver.quit()

关闭打开的应用,默认关闭当前打开的应用,所以不需要入参。这个方法并非真正的关闭应用,相当于按home键将应用置于后台,可以通过launchApp()再次启动。
driver.closeApp()
检查应用是否已经安装。需要传参应用包的名字。返回结果为Ture或False。在安装卸载的代码中我们已经使用过该方法.
driver.is_app_installed('com.tencent.mm')
将当前活跃的应用程序发送到后台。这个方法需要入参,需要指定应用置于后台的时长。
driver.runAppInBackground(2);
重置当前被测程序到出始化状态。该方法不需要入参。

 其实就是先closeApp然后在launchAPP


driver.resetApp();


posted @ 2020-06-09 17:29  嘿豆粒  阅读(204)  评论(0编辑  收藏  举报