You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Appium与Python录制iOS屏幕超过600秒?

实现iPhone设备1000秒Appium屏幕录制的解决方案

针对你用Python+Appium做自动化测试时,需要突破iPhone默认600秒录屏限制的需求,给你两个可行方案:

方案一:直接设置录制时长参数

Appium的start_recording_screen()方法支持通过duration参数指定录制时长,只要你的iOS设备和XCUITest驱动版本支持,直接传入目标时长即可:

# 启动录制,设置时长为1000秒
driver.start_recording_screen(duration=1000)

# 执行你的测试操作(这里模拟1000秒的等待,实际替换为你的测试逻辑)
import time
time.sleep(1000)

# 停止录制并保存视频
video_data = driver.stop_recording_screen()
with open("long_recording.mp4", "wb") as f:
    f.write(video_data)

注意:部分旧版本的iOS或XCUITest驱动可能对超长录制有兼容性问题,如果出现录制中断或失败,就用方案二。

方案二:分段录制后合并视频

如果单次无法录制1000秒,可拆分多次录制(比如每次590秒,避免触发默认超时),再用工具合并视频:

1. 分段录制代码

from appium import webdriver
import time

# 初始化driver(替换为你的设备配置)
desired_caps = {
    "platformName": "iOS",
    "deviceName": "iPhone",
    "appium:udid": "你的设备UDID",
    "appium:automationName": "XCUITest"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

# 分段录制,每次590秒,共2次(总时长1180秒,可根据需求调整次数)
video_segments = []
for i in range(2):
    print(f"开始第{i+1}段录制")
    driver.start_recording_screen(duration=590)
    time.sleep(590)  # 替换为对应时长的测试操作
    segment_data = driver.stop_recording_screen()
    segment_path = f"segment_{i+1}.mp4"
    with open(segment_path, "wb") as f:
        f.write(segment_data)
    video_segments.append(segment_path)

driver.quit()

2. 合并视频

用ffmpeg工具合并生成完整视频,命令行执行:

ffmpeg -f concat -safe 0 -i segments_list.txt -c copy full_recording.mp4

其中segments_list.txt内容为各分段视频的路径:

file 'segment_1.mp4'
file 'segment_2.mp4'

你也可以在Python里通过subprocess模块调用ffmpeg,实现代码内自动合并:

import subprocess

# 生成segments_list.txt
with open("segments_list.txt", "w") as f:
    for seg in video_segments:
        f.write(f"file '{seg}'\n")

# 调用ffmpeg合并
subprocess.run(["ffmpeg", "-f", "concat", "-safe", "0", "-i", "segments_list.txt", "-c", "copy", "full_recording.mp4"])

注意事项

  • 确保设备有足够的存储空间,1000秒的iOS录屏文件体积不小;
  • 测试过程中避免设备锁屏,可在设置里关闭自动锁屏;
  • 若使用方案二,确保ffmpeg已安装在你的测试环境中。

内容的提问来源于stack exchange,提问作者Gouri Sankar Das

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 19:52:37