[英]Enforce screenshot resolution with Google Chrome Headless mode
I'm having an issue with Nightwatch and Chrome when it launches in headless mode.当 Nightwatch 和 Chrome 在无头模式下启动时,我遇到了问题。 I've setup a script to take screenshots of my page which I later compare against in order to figure out what the difference is between them.
我已经设置了一个脚本来截取我的页面的屏幕截图,稍后我会与这些屏幕截图进行比较,以找出它们之间的区别。 The problem I'm running into is that depending on the machine that runs my script the screenshots are always different as they are not the same resolution.
我遇到的问题是,根据运行我的脚本的机器,屏幕截图总是不同的,因为它们的分辨率不同。
Here is a screenshot that Nightwatch captured on my Mac with a retina display.这是 Nightwatch 在我的带有视网膜显示屏的 Mac 上捕获的屏幕截图。
And here is the one which was captured in CircleCI when it ran the same script:这是在 CircleCI 运行相同脚本时捕获的一个:
Is there a way to enforce a screen resolution when launching Chrome in headless mode?在无头模式下启动 Chrome 时,有没有办法强制执行屏幕分辨率? I've worked with other libraries such as Puppeteer and it seems to be consistent across the board.
我曾与其他库(如 Puppeteer)合作过,它似乎全面一致。 The window width/height is always respected, but the size of the actual images is what's causing issues here.
窗口宽度/高度总是受到尊重,但实际图像的大小是导致问题的原因。
Here is what my launch settings look like from my Nightwatch config file:以下是我的 Nightwatch 配置文件中的启动设置:
"chrome_launch" : {
"launch_url" : "https://localhost:8000",
"globals" : {
"abortOnAssertionFailure": false,
"env" : "local"
},
"desiredCapabilities": {
"chromeOptions" : {
"args" : ["window-size=1280,2480", "headless", "disable-gpu", "hide-scrollbars"]
},
"resolution": "1440x900"
}
}
Any help would be greatly appreciated.任何帮助将不胜感激。
我遇到了同样的问题,在 chrome 中传递这个参数--force-device-scale-factor=1
对我有用:
google-chrome --headless --force-device-scale-factor=1 --window-size=1200,800
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.