0

All of my tests are failing due to chrome opening up at a size of 800x600. I've looked at several sites for a solution, but nothing I've tried seems to be working.

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1920,1080");
DesiredCapabilities cap = DesiredCapabilities.chrome();     
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setBrowserName("chrome");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
atg
  • 127
  • 2
  • 13
  • Have you tried instead using `options.addArguments("--start-maximized");` – Bill Hileman Oct 20 '17 at 19:12
  • That had no effect. Should I be worried about the Mismatched capabilities. Creating a synthetic w3c capability that i see when I start my tests – atg Oct 20 '17 at 19:30
  • The only other advice I can offer is to attempt to perform a screenshot. – Bill Hileman Oct 20 '17 at 19:32
  • The framework I've been using automatically takes screenshots on failure. This is how I've been able to determine the resolution it is currently at. – atg Oct 20 '17 at 19:34
  • And the picture looks normal? What, specifically, is the "failure" that is reported, and why is resizing part of a test of a headless browser in the first place? This may be over-simplistic, but perhaps the step that resizes the browser may need to be skipped if the browser selected for the test is determined to be headless? – Bill Hileman Oct 20 '17 at 19:39
  • The picture indicates that the site is resizing all of the elements on the page to fit as if it was displayed on a mobile device and the image resolution is 800x600 which is apparently the default headless size. The issue is the tests assumes that your browser will be bigger so the selectors are no longer valid – atg Oct 20 '17 at 20:19

3 Answers3

2

You apparently cannot resize the chrome in the headless mode . If I am not mistaken.

"options.addArguments("--headless");"

I am also assuming you are using chromedriver

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1625#c39

Shashwat
  • 23
  • 6
0

The -- is not needed for Java.

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

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

HaC
  • 902
  • 12
  • 24
0

In selenium grid, i use the following code which is working for me.

ChromeOptions options = new ChromeOptions();
options.addArguments(Arrays.asList("--window-position=0,0"));
options.addArguments(Arrays.asList("--window-size=1840,1080"));
Jayanth Bala
  • 758
  • 1
  • 5
  • 11