node.js - 可以使用 CodeceptJS 在 chrome 浏览器上使用 devtools
问题描述
我必须为 Web 应用程序编写测试,而且我必须在移动 chrome 浏览器上使用它们。在测试期间是否有可能使用 chrome devtools 和移动设备模拟器?
感谢帮助
解决方案
对于 Puppeteer,在配置中使用带有 defaultViewport 值的 chrome 选项。
https://codecept.io/helpers/Puppeteer/#configuration https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
"Puppeteer": {
"url": "https://rambler.ru",
"browser": "chrome",
...
"chrome": {
"defaultViewport": {
"width": 640,
"height": 360,
"deviceScaleFactor": 1,
"isMobile": true,
"hasTouch": true,
"isLandscape": false
}
}
}
或者page.emulate()
在每次测试之前
使用https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageemulateoptions
UPD:添加 page.emulate 示例
使用page.emulate
:在自定义助手中,创建自己的函数,该函数将与页面一起使用,例如:
async emulateDevice(options) {
const currentPage = this.helpers['Puppeteer'].page;
await currentPage.emulate(options);
}
其中选项是具有视口和 userAgent 的对象: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageemulateoptions https://codecept.io/helpers/Puppeteer/#access-from-helpers
然后在测试中:创建选项:
const myCustomViewPort = {
viewport: {
width: 640,
height: 360,
deviceScaleFactor: 1,
isMobile: true,
hasTouch: true,
isLandscape: false
},
userAgent: ""
}
您可以在代码中调用它:
Before(async (I) => {
await I.emulateDevice(myCustomViewPort);
});
推荐阅读
- django - Django:查询相互关联的模态......如何最好地实现预取或选择相关?
- authentication - Zabbix web场景zul登录表单
- scala - 如何发送 MultipartForm 请求
- sql - 在 SQL (Impala) 中,如何计算满足条件的行与下一个行之间的时间增量?
- .net - app.box .NET SDK 返回空的项目集合
- node.js - 错误接收器-[onTurnError]:TypeError:无法读取未定义的属性“getTeamDetails”
- c# - 从 C# 中杀死一个远程 linux 进程
- selenium - 线程“主”org.openqa.selenium.NoAlertPresentException 中的异常:尝试使用 Selenium 和 Java 解除警报时没有此类警报
- azure - ISTIO 内部流量路由是否可以使用自定义网关?
- typescript - 这个类型声明中的 { 0: T } 是什么意思?