Search code examples
selenium-webdriverjenkinsvmwarescreen-resolutionjenkins-agent

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


I'm having trouble running some Selenium tests on a Jenkins agent. 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 agent is a virtual machine (Windows Server 2012 R2). The Jenkins agent is Connected via JNLP agent. The agent 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 agent 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!


Solution

  • 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!