How to write script in python to reboot android tablet multiple times

别说谁变了你拦得住时间么 提交于 2019-12-11 17:34:02

问题


How can I write script in python to reboot android tablet and launch any app multiple times. Is there any better way to automate this test.


回答1:


you can use the command adb reboot to reboot a device.

There are likely a plethora of ways you could use python to make this adb command. The simplest of which that I can think of is:

import os
os.system("adb reboot")

you'll have to either put a path infront of adb, run this from the folder that adb is in, or add the folder that adb is in to your system path variable.

If you don't want to go that route (or if you want to do some other more ineteresting things with adb) there exists a python wrapper around the adb tool that will let you interact with it in a more "pythonic" way than simply running system cmds.




回答2:


#!/usr/bin/python

import os, time

for iter in xrange(5):

    adb_reboot = os.popen("sudo adb reboot")
    print(adb_reboot)
    print('Phone is rebooting...')
    time.sleep(15)

    adb_wait = os.popen("sudo adb wait-for-device")
    print(adb_wait)
    time.sleep(15)
    print('Phone rebooted successfully')

    adb_device = os.popen("sudo adb devices -l")
    print(adb_device)


来源:https://stackoverflow.com/questions/19171297/how-to-write-script-in-python-to-reboot-android-tablet-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!