Set Window Size in Headless execution
In this article we will learn how to set window size during headless execution with coded tests as well as by utilizing the Smart Recorder.
To set the screen size during headless execution by utilizing the test recorder, you need to have the Web Extensions addon and look for Set windows size action. You can find it here: https://addons.testproject.io/web-extensions. After the first step of "Navigate to" action add a step of "Set window size"
Then, select the Set Window Size and supply the required size.
You can also use the Maximize Screen action if you wish it to run on full screen.
That's it, now you run your test in headless mode with the desired solution!
In your coded test you can easily change the window size by using the driver instance.
// We get the instance for the web driver
WebDriver driver = helper.getDriver();
// set the window to the dimension we want, for example 1440, 900
driver.manage().window().setSize(new Dimension(1440, 900));
// With this line we can set it to full screen
For BrowserStack you will need to provide a custom capability as described here:
Into the Job: