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

公众号:自动化测试实战

相关推荐
富贵儿9983 小时前
NL2SQL 实践手记 08:SQL 没报错,答案为什么不对——从失败复盘到 Workflow 修复
数据库·python·sql·ai·自然语言处理·langchain
无巧不成书02185 小时前
最新 PyPI可信发布完整教程 GitHub Actions+OIDC零Token实现Python包自动化发布
python·自动化·github·pypi
东莞市云毅网络有限公司9 小时前
用 Node 做收录快照的周对比:差集、阈值与告警
python·sqlite·自动化运维·geo·数据监测
山楂树の10 小时前
Python Pandas 数据处理:数据读取、筛选、清洗、排序与分组
开发语言·python·pandas
Logintern0910 小时前
langgraph 图编译的聊天机器人
python·langgraph
xurileidian11 小时前
第 22 篇 · 边玩边学Python · 双等号与 is 不是一回事
开发语言·python·spring
钱栈up13 小时前
GitHub热榜实测|Sherlock:一个用户名搜遍全网
python·开源·github
geovindu13 小时前
python: Gradient Boosting
开发语言·后端·python·算法·boosting
Agent世界14 小时前
发布台账字段漂移:1265 条记录里 190 条没有标题
python·自动化运维