如何使用TestCafe在Firefox中启用设备仿真运行测试
在Firefox中用TestCafe启用设备仿真的方法
你可以通过两种方式在Firefox中为TestCafe测试启用设备仿真:
一、命令行参数方式
使用预设设备
直接用--emulate-device参数指定TestCafe内置的设备型号,比如模拟iPhone X:
testcafe "firefox" tests/sample-fixture.js --emulate-device "iPhone X"
想要查看所有支持的预设设备,执行以下命令:
testcafe --list-devices
自定义仿真参数
如果需要自定义屏幕尺寸、像素比、触摸支持等参数,使用--emulation参数,示例:
testcafe "firefox" tests/sample-fixture.js --emulation "width=375;height=812;deviceScaleFactor=2;touch=true"
可配置的参数包括width、height、deviceScaleFactor、touch、userAgent等,用分号分隔。
二、测试代码内配置
如果需要针对特定测试用例或测试集设置设备仿真,可以在代码中通过fixture.emulate()或test.emulate()方法配置:
fixture('示例测试集') .page('https://example.com') // 使用预设设备 .emulate({ device: 'iPhone X' }); // 或者自定义仿真参数 fixture('自定义设备仿真') .page('https://example.com') .emulate({ width: 412, height: 915, deviceScaleFactor: 2.75, touch: true, userAgent: 'Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36' }); test('示例测试', async t => { // 测试逻辑 });
内容的提问来源于stack exchange,提问作者msilori
相关产品推荐
相关产品推荐

