Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 879
jurgenvo Avatar asked Mar 14 '17 11:03

jurgenvo


People also ask

Why can't I run Selenium tests on a Jenkins slave?

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:

What is the default screen resolution for Selenium tests?

By default, all Selenium tests on desktop run on a screen resolution of 1920x1080. You can use our custom resolution capability which lets you specify a different screen resolution for your tests. Note: Browser window is not maximized upon launch in any Selenium test. Changing the resolution will not maximize browser.

How to check the display resolution of Jenkins slave?

To check the display resolution, we log the display height and width to the console, using: 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.

How to setup selenium on a Linux VM?

How to setup Selenium on a Linux VM. 1 Step 1. Whenever y o u get a new Linux machine, always update the packages first. Then install the necessary dependencies. 2 Step 2. 3 Step 3.


1 Answers

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!

like image 84
jurgenvo Avatar answered Sep 17 '22 12:09

jurgenvo