Chrome的“–headless=new”模式不允许应用“–window-size”选项。

huangapple go评论50阅读模式
英文:

Chrome "--headless=new" mode does not allow to apply "--window-size" option

问题

当使用新的 Chrome 无头模式时,"--windows-size=width,height" 参数不起作用。
例如:
"--headless=new",
"--window-size=1920,1080"
使用这些参数运行测试会产生奇怪大小的截图:1028x653 像素

但是对于旧的无头模式:
"--headless",
"--window-size=1920,1080"
截图的大小是正确的:1920x1080 像素。

我不能使用旧模式,因为它不再支持文件下载,这里是一个关于此的帖子,在其中建议使用新的无头模式作为解决方案:https://stackoverflow.com/q/45631715/21205827

英文:

When new chrome headless mode is used the "--windows-size=width,height" argument doesn't work.
For example:
"--headless=new",
"--window-size=1920,1080"
Running tests with these arguments produces strange size screenshots: 1028x653 px

But with the old headless mode:
"--headless",
"--window-size=1920,1080"
the screenshots size is OK: 1920x1080 px.

I can't use old mode, because the files downloading is not working in it anymore, here is the post about it, where using the new headless mode is suggest as a solution: https://stackoverflow.com/q/45631715/21205827

答案1

得分: 3

我们也遇到了相同的问题。在问题解决之前,我们的解决方法是缩小视图。我们添加了参数 force-device-scale-factor=0.75

英文:

We came accross the same issue. Until the bug is solved, our workaroud is zooming out. We added argument force-device-scale-factor=0.75.

答案2

得分: 0

你是否正在使用像Jenkins这样的CI工具运行你的测试?
我看到类似的行为(混乱的屏幕尺寸)只发生在像Jenkins这样的中心运行中,就像一直在本地运行正常一样。
如果是这样,我认为与通过Jenkins代理执行测试的系统用户有关。

英文:

Are you running your tests with a CI-Tool like Jenkins?
I see a similar behavior (messing up the screen size) only with a central run on Jenkins, like always..local it works.
If so I think it has to do with the system user the test is executed through a jenkins agent.

答案3

得分: 0

我面对过这个确切的问题!幸运的是,我找到了一个解决方法!对于Java,不使用***--window-size=1920,1080***,我使用了以下代码:

driver.manage().window().setSize(new Dimension(1920, 1080));

我还移除了屏幕最大化,这对我有用!

请尝试上述代码,或者对于你正在使用Selenium的语言使用等效的代码!

附言:我正在使用xvfb运行Selenium!所以如果你在屏幕大小方面遇到问题,你可能要研究一下这个。

英文:

I faced this exact problem! Luckily I found a workaround! For java instead of --window-size=1920,1080 I did:

driver.manage().window().setSize(new Dimension(1920, 1080));

I also removed screen maximisation and it worked for me!

Please try above code or it's equivalent for the language you are using selenium with!

P.S.: I'm running selenium with xvfb! so if you have issues with screen size, you might look into that

huangapple
  • 本文由 发表于 2023年2月14日 02:19:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定