docker - Docker 容器中的 Headless Cypress 分辨率始终为 1280x1024
问题描述
当我在官方 docker 容器(图像)中运行我的测试时,cypress/included:7.5.0
浏览器总是只有 1280x1024。在主机上运行相同的配置、相同的规格等时,我得到了所需的 1920x1080。
我的 cypress.json:
{
"viewportHeight": 1080,
"viewportWidth": 1920,
"chromeWebSecurity": false,
"baseUrl": "http://phoenix:4000",
"watchForFileChanges": false,
"requestTimeout": 40000,
"defaultCommandTimeout": 40000,
"pageLoadTimeout": 80000,
"video": false,
"env": {
"codeCoverage": {
"url": "http://phoenix:4000/__coverage__",
"expectBackendCoverageOnly": false
}
}
此外,我添加了一些类似的配置,您可以在此处找到它的解释:https ://docs.cypress.io/api/plugins/browser-launch-api#See-all-Chrome-browser-switches
我的插件/index.js:
module.exports = (on, config) => {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--window-size=1920,1080');
launchOptions.args.push('--force-device-scale-factor=1');
launchOptions.args.push('--start-fullscreen');
}
return launchOptions;
});
require('@cypress/code-coverage/task')(on, config);
return config;
};
为什么从 docker 容器 ( ./node_modules/.bin/cypress run --browser chrome
) 中运行时仍然获得 1280x1024 分辨率?
解决方案
我明白了,我需要先启动我自己的 Xvfb 服务器:
Xvfb -screen 0 1920x1080x24 :99 & export DISPLAY=:99 && ./node_modules/.bin/cypress run --browser chrome && pkill Xvfb
来源:https ://docs.cypress.io/guides/continuous-integration/introduction#Xvfb
推荐阅读
- python - 为什么安装pygobject会出错并且无法进一步安装
- javascript - 如何在 npm 上发布 typescript ReactJS 组件?
- cloudinary - 使用多个标签的 Cloudinary Search API
- javascript - javascript和单选按钮的this.value
- r - 使用 ggplot2 绘制一组内的两个变量
- php - 如何使用 Laravel 6 创建分页?
- android - 无法使用 Espresso 在 editText 对话框中键入文本
- php - Web 应用程序无法访问 MySQL/MariaDB
- android - 为什么我的 Kotlin MySQL 应用程序中没有找到合适的驱动程序错误?
- c# - 有没有办法缩短此代码:(如果键不存在,则将键添加到字典中)?