How to set the browser window size when using `google-chrome --headless`?

那年仲夏 提交于 2019-11-29 23:45:07

Found it, simply pass --window-size command line argument to Google Chrome, for example --window-size=1920,1080

In a Protractor config this would look like this:

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['headless', 'window-size=1920,1080']
    }
}

The cool thing is that the windows size is not limited to the current display, is truly headless meaning in can be as large as needed for the tests.

Java code:

options.addArguments("window-size=1920,1080");

I expand a bit more on this here: https://stackoverflow.com/a/43542416/511069

I realize this is a bit late, but why not just use the built in selenium?

    aDriver.manage().window().setSize(new Dimension(width, height));

Works like a champ. I've used it for FireFox, Chrome (even headless), and Edge.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!