monkeyrunner入门之安装卸载app(一)

一、配置monkeyrunner环境(这里就不多说,进网址看看就好了,很简单的)
https://www.cnblogs.com/lynn-li/p/5885001.html

记得确认手机连接了电脑(adb devices 这句命令)
二、打开cmd,直接终端,运行python文件(有两种方法可以运行monkeyrunner,这里就说运行python文件)
1、python文件(installApp.py
在这里插入图片描述
2、终端输入:(monkeyrunner后面加apk包的位置,直接把apk包拖进终端就好)
在这里插入图片描述
3、你会发现已经好了,完美,下面的贴出代码供你们复制:

   #coding:utf-8
#保存文件格式记得选择utf-8,默认是ansi
# 引入本程序所用到的模块
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

# 连接手机设备
device = MonkeyRunner.waitForConnection()

# 截图
result = device.takeSnapshot()

# 将截图保存到文件 
result.writeToFile('C:\\Users\\shenzixinsx\\Desktop\\monkeyrunner\\installApp\\Test1_001.png','png')

# 安装新的APP
device.installPackage('C:\\Users\\shenzixinsx\\Desktop\\monkeyrunner\\installApp\\Relax-release_v1.4.1_vc16_svn7544.apk')
print ('Install Success!')

# 暂停5秒
MonkeyRunner.sleep(5)

# 截图
result = device.takeSnapshot()
result.writeToFile('C:\\Users\\shenzixinsx\\Desktop\\monkeyrunner\\installApp\\Test1_002.png','png')


# 卸载APP
device.removePackage('com.meditation.deepsleep.relax')
print ('Uninstall Success!')


# 截图
result = device.takeSnapshot()
result.writeToFile('C:\\Users\\shenzixinsx\\Desktop\\monkeyrunner\\installApp\\Test1_003.png','png')

猜你喜欢

转载自blog.csdn.net/shenzixincaiji/article/details/85121375