Warm tip: This article is reproduced from serverfault.com, please click

How to increase the screen resolution on Test Agent in TFS 2015

发布于 2020-12-05 06:03:08

I'm using TFS 2015 to trigger Selenium automated test suite. Few of test cases are failing due to some HTML elements get overlapped and this happens due to the screen resolution of the session which TFS service account opens is smaller (Programmatically I took screenshots while running the test methods in TFS). All the test cases are passing when I run from Visual Studio or through CMD locally or Remote Desktop session in TFS server.

I tried increasing the screen resolution using bellow techniques , but still screenshots saved in TFS server shows smaller screen size.

  1. Increase the window size :

driver.Manage().Window.Size = new Size(x, y);

  1. Chrome capabilities - Resolution
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("resolution", "1920x1080");
  1. Chrome capabilities - Window Size
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--window-size=1300,1000");
  1. Maximize the window driver.manage.window.maximize();

None of these approaches works since the screen resolution of the session which TFS service account opens is smaller.

When I run the test cases with Headless option, browser windows opens with Maximum window size but test fails since selenium can't identify the elements (NoSuchElementException) :

var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("headless");

(Project which I'm automating is a ReactJS project)

I would like to know a way to increase the screen size when test are being executed form TFS agent. Thank You

Questioner
shalinds
Viewed
0
PDHide 2020-12-06 02:13:09
chromeOptions.addArgument("--headless");
chromeOptions.addArgument("--disable-gpu");
chromeOptions.addArgument("--window-size=1920,1080")

WebDriver driver  = new ChromeDriver(chromeOptions);

don not use browser.maximize after this it will reset the windows size to system default.

Try also:

chromeOptions.addArguments("--headless","--disable-gpu","--window-size=1920,1080")

WebDriver driver  = new ChromeDriver(chromeOptions);

Debugging tips

See if the test are passing with same window size but non headless mode

If it does pass then it is because of faster execution speed , headless browser is faster than non headless browser so you need to add more explicit waits for those elements