install_apk.py【轉發】

# encoding=utf-8
# Filename:install_apk.py
#導入此程序所需要的monkeyrunner模塊
#from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

#鏈接當前設備,返回一個MonkeyDevice對象
device = MonkeyRunner.waitForConnection
if not device:
    print ("Please connect a device to start")
else:
    print ("Start")
device.installPackage('d:\code\python\[xx.apk]')
MonkeyRunner.sleep(10)
print ('Install success')
#啓動一個Activity
device.startActivity(component='[com.sohu.newslient/com.sohu.newsclient.app.SplashActivity]')
#等待10秒
MonkeyRunner.sleep(10)
print ('Starting success')

#手機端運行應用的截屏
result1=device.takeSnapshot()
#保存截圖的路徑
result1.writeToFile('d:\\code\\python\\3\shot.png','png')
print ('Sreenshot success')
MonkeyRunner.sleep(10)
#卸載
device.removePackage('[com.sohu.newsclient]')
print ('Uninstall success')

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章