Setting display resolution for Selenium tests on virtual machine as Jenkins Slave

jurgenvo picture jurgenvo · Mar 14, 2017 · Viewed 8.5k times · Source

I'm having trouble running some Selenium tests on a Jenkins Slave. To be specific, the display resolution that is used to run the tests is too small, causing some of the tests to fail.

To check the display resolution, we log the display height and width to the console, using:

driver.manage().window().maximize();
System.out.println("Window height: " + driver.manage().window().getSize().getHeight());
System.out.println("Window width: " + driver.manage().window().getSize().getWidth());

This returns:

Window height: 784
Window width: 1040

which seems like a very strange resolution to me. The desired resolution is 1920 x 1080.

The server that is used as a slave is a virtual machine (Windows Server 2012 R2). The Jenkins Slave is Connected via JNLP agent. The slave has the service running with Log On As "Local System" with the "Allow service to interact with desktop" option enabled.

So far we've tried a number of things like:

  • Connecting to slave VM using RDP and disconnecting to leave session open with desired display resolution
  • Using powershell to set the display resolution
  • Setting the default display resolution in the VM configuration
  • Setting the window dimensions using Selenium
  • And more...

All of these didn't resolve the issues. Suggestions are very welcome!

Answer

jurgenvo picture jurgenvo · Mar 15, 2017

Finally managed to fix these issues after realizing that Jenkins does not necessarily need to run the slaves as a windows service. To start the slave, the JNLP agent can be downloaded from Jenkins and copied to the server. When running the JNLP file, you can select for the option to install the slave agent as a service.

Jenkins slave agent

Previously we had this option selected, that's why the slave was running as a service. After stopping and removing the service, we ran the JNLP file again and made sure to not select the option.

The solutions suggested that included disconnecting the remote desktop session and leaving the session open with a large resolution didn't work when running the slave as a service. They do work however when running the slave in the default way.

Make sure that the remote desktop session is not ended after a certain period of time: Session timeout properties

Hope this helps someone!