使用 Selenium 在 Headless Chrome 中全屏显示 [英] Fullscreen in Headless Chrome using Selenium

本文介绍了使用 Selenium 在 Headless Chrome 中全屏显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 E2E 套件中进行了许多测试,其中视频元素全屏显示并验证全屏状态.但是,在无头运行套件时,这些测试会失败.该页面的屏幕截图显示视频根本没有全屏显示,即使在单击全屏按钮后也是如此.有没有办法在无头 Chrome 中实现全屏功能?

这是我的配置中的功能示例.

功能:[{'浏览器名称':'铬','goog:chromeOptions': {args: ['无头']}}]

解决方案

当添加参数 --start-fullscreen 来初始化


虽然


结论

因此可以得出结论,在--headless模式下,Chrome浏览器总是以800 x 600px 大小忽略自定义的 --window-size 参数.

I have a number of tests in an E2E suite where a video element is fullscreened and the fullscreen status is verified. However, when running the suite headlessly, these tests fail. Screenshots of the page show the video is simply not in fullscreen, even after the fullscreen button is clicked. Is there a way to achieve fullscreen functionality in headless Chrome?

Here is an example of the capabilities in my config.

capabilities: [
    {
        'browserName': 'chrome',
        'goog:chromeOptions': {
            args: ['headless']
        }
    }
]

解决方案

When the argument --start-fullscreen is added to initialize in normal mode it seems the screen size is:

1366 x 724px

Snapshot:


Whilst when initiated additionally with either of the arguments:

  • --start-maximized
  • --kiosk
  • --start-fullscreen

The resultant screen size is always:

800 x 600px

Snapshot:


Conclusion

So it can be concluded that in --headless mode Chrome browser always opens in 800 x 600px size ignoring the customized --window-size arguments.

这篇关于使用 Selenium 在 Headless Chrome 中全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆