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

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


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!


Based on my experience with this you can't solve this problem programmatically. Your tests will run on the resolution which was used last time when you physically accessed this VM's display. For example, if I open VM on my big screen monitor and maximize it, tests will run on that resolution. But if I open it on my laptop screen and close RDP connection, tests will run on that smaller screen size.I know it sounds strange, but I really couldn't find better solution. :D So now I must be careful to maximize VM display on my bigger screen before I close VM. You will probably dislike this answer, but remember it when you find yourself out of other solutions. ;)


Solution that worked for me is to run Chrome in a 'headless' mode (without GUI). It works with Jenkins Agent running as a service, when GUI is not available.Here is the code sample of the web driver initialization:

var options = new ChromeOptions();options.BinaryLocation = @"C:\Program Files\Google\Chrome\Application\chrome.exe";options.AddArgument("Headless");options.AddArgument("window-size=1920,1080");driver = new ChromeDriver(@"<path>\Selenium.WebDriver.ChromeDriver.2.37.0\driver\win32", options);