iOS自动化录屏在Chrome浏览器打不开处理方法

在iOS自动化测试时,生成的allure测试报告当有视频日志时,iOS的录屏chrome打不开,safari可以,这是因为iPhone的录屏压缩格式是:mjpeg ,chrome可能不支持;将ffmpeg转换到H264即可正常打开

python 复制代码
@pytest.fixture(scope="module", autouse=True)
def index_reset(driver_init, request):
    driver = driver_init
    driver.start_recording_screen(**record_options)
    log.info(f"{request.module.__name__} 开始录屏")
    yield
    log.info(f"{request.module.__name__} 运行结束")
    log.info("index reset teardown")

    video_base64 = driver.stop_recording_screen()
    video = base64.b64decode(video_base64)
    mp4_file_name = f"./outputs/videos/{run_uuid}_{request.module.__name__}.mp4"
    with open(mp4_file_name, "wb") as file:
        file.write(video)
    output_file_name = f"./outputs/videos/{run_uuid}_{request.module.__name__}_new.mp4"
    # 使用FFmpeg处理视频: ffmpeg -i a6d4eb0e60b8cab1.mp4 -c:v libx264 -crf 23 -c:a aac a6d4eb0e60b8cab1_new.mp4
    try:
        subprocess.run([
            'ffmpeg',
            '-i', mp4_file_name,
            '-c:v', 'libx264',
            '-crf', '23',
            '-c:a', 'aac',
            output_file_name
        ], check=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        print(f"视频处理完成,保存为: {output_file_name}")
    except subprocess.CalledProcessError as e:
        print(f"FFmpeg处理失败: {e.stderr.decode()}")
    allure.attach.file(output_file_name,
                       name=f"{request.module.__name__}_new录屏视频",
                       attachment_type=allure.attachment_type.MP4,
                       extension="mp4")

driver_init代码

ini 复制代码
"""
config.py文件
capabilities_ios = dict(
    platformName='iOS',
    automationName='XCUITest',
    udid='XXXXX-XXX-XXX',  # 设备名
    bundleId='com.xxx.com',  # app入口
)
record_options = {
    # 'timeLimit': '180',  # 录屏时长限制,单位秒
    'videoSize': '1080x1920',  # 视频分辨率
    'bitRate': 400000,  # 视频比特率
    'fps': 15  # 帧率
}
"""
@pytest.fixture(scope="session", autouse=True)
def driver_init(request):
    ...
    driver = webdriver.Remote(appium_server_url, options=XCUITestOptions().load_capabilities(capabilities_ios))
    yield driver
    log.info("session driver quit")
    driver.quit()

这样,iOS自动化录屏文件在Chrome浏览器也可以查看了。

公众号:自动化测试实战

相关推荐
电商API&Tina几秒前
合规电商数据采集 API|多平台实时数据抓取,告别爬虫封号风险
大数据·开发语言·前端·数据库·爬虫·python
天才测试猿2 分钟前
自动化测试用例编写
自动化测试·软件测试·python·测试工具·程序人生·职场和发展·测试用例
忘忧记2 分钟前
基于Tkinter基础模板的开发流程指南
开发语言·python
姚瑞南3 分钟前
【AI 风向标】强化学习(RL):智能体自我优化的学习范式
人工智能·经验分享·python·gpt·深度学习·学习·机器学习
Zomcxj4 分钟前
PasteLabel 图像编辑器:贴图标注,解决样本采集难题
人工智能·python·编辑器·贴图
未定义.2215 分钟前
第4篇:企业级框架搭建,Pytest+PO模式从0到1实战
python·ui·自动化·jenkins·集成测试·pytest
轻竹办公PPT5 分钟前
AI 生成 PPT 真能替代人工吗?多款工具深度测试
人工智能·python·powerpoint
文人sec8 分钟前
pytest2-Allure自动化测试报告
python·功能测试·自动化·pytest
ILUUSION_S9 分钟前
langchain核心组件Tools
python·langchain
tjjucheng8 小时前
靠谱的小程序定制开发哪个好
python