I tried setting the browser size on Chrome --headless by using Selenium WebDriver commands.
I get this WebDriver error:
- Failed: un
I had a problem with screen resolution when running on Jenkins (which forces headless mode). The solution was very simple: set headless mode to true explicitly. For some reason, not doing this explicitly caused my screen to "shrink" causing all kinds of "element intercept click" issues. Because I was taking screenshots during failures, I noticed the resolution (size) was not right. Once I did this, the problem went away; confirmed by screenshots taken during failures.
To avoid conflicts with local configurations, I moved the value of this flag into a configuration file that was then added to our .gitignore file to prevent accidental overwrites.
If you are like me, where none of these commonly solutions worked out, make sure you explicitly set this value:
ChromeOptions options = new ChromeOptions();
...
String headlessMode = readProperty("headless_mode"); // Get value from some prop file (my own implementation)
options.setHeadless(Boolean.valueOf(headlessMode));
...
driver = new ChromeDriver(options);
If you don't want (or need) this separation, simply set the value to true in the setHeadless method call.