Ejemplo n.º 1
0
 def reboot():
     """
     retboot devices
     :return:
     """
     command = "reboot"
     adb_cmd(command)
Ejemplo n.º 2
0
 def adb_image(path):
     shell_cmd("rm /sdcard/screenshot.png")
     shell_cmd("/system/bin/screencap -p /sdcard/screenshot.png")
     log.info(">>>截取屏幕成功,在桌面查看文件。")
     c_time = time.strftime("%Y_%m_%d_%H-%M-%S")
     image_path = os.path.join(path, c_time + ".png")
     adb_cmd('pull /sdcard/screenshot.png %s"' % image_path)
Ejemplo n.º 3
0
 def sync(directory, **kwargs):
     '''
     # 同步更新 很少用此命名
     '''
     command = "sync %s" % directory
     if 'list' in kwargs:
         command += " -l"
         result = adb_cmd(command)
         return result
Ejemplo n.º 4
0
 def get_ui_dump_xml(xml_path):
     """
     获取当前Activity的控件树
     """
     PATH = lambda a: os.path.abspath(a)
     if int(Actions.get_sdk_version()) >= 19:
         shell_cmd(
             "uiautomator dump --compressed /data/local/tmp/uidump.xml")
     else:
         shell_cmd("uiautomator dump /data/local/tmp/uidump.xml")
     path = PATH(xml_path)
     if not os.path.isdir(path):
         os.makedirs(path)
     adb_cmd("pull /data/local/tmp/uidump.xml %s" % PATH(path)).wait()
     shell_cmd("rm /data/local/tmp/uidump.xml").wait()
     if os.path.exists(os.path.join(path, "uidump.xml")):
         return True
     else:
         return False
Ejemplo n.º 5
0
 def device_ready(devics_sn=""):
     '''
     get device state
     device:设备正常连接
     offline:连接出现异常,设备无响应
     unknown:没有连接设备
     no device return error: no devices/emulators found
     more then one device return error: more than one device/emulator
     :return:
     '''
     if devics_sn == "":
         result = adb_cmd("get-state")
     else:
         result = adb_cmd("-s {0} get-state".format(devics_sn))
     if result.strip() == "device":
         return True
     else:
         log.error("the state device is " + result)
         return False
Ejemplo n.º 6
0
 def get_app_pid(pkg_name):
     '''
     # 根据包名得到进程id
     '''
     result = adb_cmd("shell ps | {0} ".format(Actions.find_type) +
                      pkg_name)
     if result == '':
         return "the process doesn't exist."
     result = result.split(" ")
     return result[7]
Ejemplo n.º 7
0
 def open_app(packagename, activity):
     '''
     打开指定app
     '''
     result = adb_cmd("shell am start -n %s/%s" % (packagename, activity))
     check = result.partition('\n')[2].replace('\n', '').split('\t ')
     if check[0].find("Error") >= 1:
         return False
     else:
         return True
Ejemplo n.º 8
0
 def get_all_devices():
     '''
     get device list
     :return:
     '''
     devices = []
     result = adb_cmd("devices")
     for device in result.strip("\r\n").split("\r\n"):
         sn = device.replace("\tdevice", "")
         if "devices" not in sn and sn != "":
             devices.append(sn)
     return devices
Ejemplo n.º 9
0
 def adb_video(path, times=20):
     """
     android6 可以
     """
     PATH = lambda p: os.path.abspath(p)
     sdk = int(Actions.get_sdk_version())
     if sdk >= 19:
         shell_cmd(
             "screenrecord --time-limit --size 640 * 360 %d --verbose /data/local/tmp/screenrecord.mp4"
             % times)
         log.info(">>>Get Video file...")
         time.sleep(1.5)
         path = PATH(path)
         if not os.path.isdir(path):
             os.makedirs(path)
         c_time = time.strftime("%Y_%m_%d_%H-%M-%S")
         adb_cmd("pull /data/local/tmp/screenrecord.mp4 %s" %
                 PATH("%s/%s.mp4" % (path, c_time)))
         # shell_cmd("rm /data/local/tmp/screenrecord.mp4")
     else:
         log.error("sdk version is %d, less than 19!" % sdk)
         sys.exit(0)
Ejemplo n.º 10
0
 def pull(remote, local):
     '''
     # 拉数据到本地
     '''
     result = adb_cmd("pull %s %s" % (remote, local))
     return result
Ejemplo n.º 11
0
 def push(local, remote):
     '''
     # 将电脑文件拷贝到手机里面
     '''
     result = adb_cmd("push %s %s" % (local, remote))
     return result
Ejemplo n.º 12
0
 def do_fastboot():
     """
     进入fastboot模式
     """
     adb_cmd("reboot bootloader")
Ejemplo n.º 13
0
 def uninstall_app(pkg_name):
     """
         卸载应用args:- packageName -:应用包名,非apk名
     """
     adb_cmd(" uninstall %s" % pkg_name)
Ejemplo n.º 14
0
 def install_app(appFile):
     """
     安装app,app名字不能含中文字符
     """
     adb_cmd("install -r %s" % appFile)