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浏览器也可以查看了。

公众号:自动化测试实战

相关推荐
Naiva8 分钟前
【小技巧】PyCharm建立项目,VScode+CodeX+WindowsPowerShell开发Python pyQT6
vscode·python·pycharm
nvd1121 分钟前
asyncio.run() vs asyncio.gather():启动器与聚合器, 为何Jupyter notebook里能直接使用await?
开发语言·python·jupyter
EEG小佬29 分钟前
Jupyter选择内核时如何找到虚拟环境
ide·python·jupyter
文人sec42 分钟前
使用python-pandas-openpyxl编写运营查询小工具
开发语言·python·pandas
hu_yuchen1 小时前
问卷系统自动化测试报告
软件测试·python
百锦再1 小时前
第8章 模块系统
android·java·开发语言·python·ai·rust·go
Ashlee_code1 小时前
经纪柜台系统解析:从今日国际金融动荡看证券交易核心引擎的变革
python·架构·系统架构·区块链·vim·柜台·香港券商
清空mega2 小时前
从零开始搭建 flask 博客实验(4)
后端·python·flask
咋吃都不胖lyh3 小时前
比较两个excel文件的指定列是否一致
爬虫·python·pandas
0小豆04 小时前
【系列开篇】从零构建智能字幕校准系统:一个AI+微服务的完整实战之旅
spring boot·python·nlp·微服务架构·实战项目·spacy·ai算法