brief introduction : In some special situations , Passed adb Connect , Then you can take a screenshot , Recording screen , Crawl log operation .
Related strategies :
adb:5 Seconds to finish viewing App Package name and startup page Activity
adb Restart or shut down the phone
adb: The android mobile phone USB Debug mode
adb:win10 Installation under system
adb: Common commands
Case study 1: Screenshot
# Screenshot
adb shell screencap /sdcard/202206280928.png
# Pull screenshot
adb pull sdcard/202206280928.png ./
Case study 2: Recording screen , Press Ctrl+C Stop recording
# Recording screen
adb shell screenrecord /sdcard/202206280932.mp4
# Pull screenshot
adb pull /sdcard/202206280932.mp4 ./
Case study 3: Grab logs , Press Ctrl+C Stop grabbing
adb logcat -v time >.\log"%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%-%time:~3,2%-%time:~6,2%.txt"
Transform into Python Script form :
# -*- coding: utf-8 -*-
# time: 2022/6/28 10:18
# file: adb_test.py
# author: tom
# official account : Play with test development
import os
import time
import datetime
import subprocess
import threading
class ADB:
def __init__(self, device, target_path):
self.target_path = target_path
subprocess.Popen(f"adb connect {
device}")
def screenshot(self):
# Use && separate .
file_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
step1 = rf"cd {
self.target_path}"
step2 = f"adb shell screencap /sdcard/{
file_name}.png"
step3 = f"adb pull sdcard/{
file_name}.png ./"
command = fr"{
step1} && {
step2} && {
step3}"
os.popen(command)
def video(self, record_time):
# collection
file_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
step1 = rf"cd {
self.target_path}"
step2 = f"adb shell screenrecord --time-limit {
record_time} /sdcard/{
file_name}.mp4"
command = fr"{
step1} && {
step2}"
os.system(command)
# Pull
step4 = rf"adb pull sdcard/{
file_name}.mp4 ./"
command2 = fr"{
step1} && {
step4}"
os.system(command2)
if __name__ == '__main__':
device = "192.168.xxx.xxx"
target_path = r"C:\adbTest\test"
adb = ADB(device, target_path)
adb.screenshot()
adb.video(10)
WeChat official account : Play with test development
Welcome to your attention , Common progress , thank you !