Python实现Appium录屏功能

# coding:utf-8
from time import sleep
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

desired_caps = {}
# 系统
desired_caps['platformName'] = 'Android'
#手机版本,在手机中:设置--关于手机   #命令行获取手机的版本号:adb -s da79fc70  shell getprop ro.build.version.release
desired_caps['platformVersion'] = '10'
# 设备号       adb devices
# desired_caps['deviceName'] = 'emulator-5554'
desired_caps['deviceName'] = '9b2157cfaedb'
# 包名   命令行获取包名和启动名:adb shell "dumpsys window | grep mCurrentFocus"
desired_caps['appPackage'] = 'com.android.settings'
# 启动名
desired_caps['appActivity'] = 'com.android.settings.Settings'
# desired_caps["resetKeyboard"] = "True"#程序结束时重置原来的输入法
# desired_caps["noReset"] = "True"#不初始化手机app信息(类似不清除缓存)
# 声明手机驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
driver.start_recording_screen(timeLimit=1500)   # timeLimit默认3分钟,超过3分钟,需要设置时间长度
The timeLimit value must be in range [1, 1800] seconds. 
WebDriverWait(driver,60)

driver.hide_keyboard()
sleep(3)
record = driver.stop_recording_screen()

import base64
data= base64.b64decode(record)  #转换成base64编码数据
with open('sample.mp4', 'wb') as file:
    file.write(data)
# 退出手机驱动对象
driver.quit()

你可能感兴趣的:(Appium自动化,Python,android)