-1

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

shalinds
  • 63
  • 2
  • 8

1 Answers1

1
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

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • I tried the solution which you have given but test cases fail with NoSuchElementException erros. Thank You ! – shalinds Dec 05 '20 at 16:38
  • @shalinds are you sure you are not maximising browser anywhere , also cahnge the windows size to that of your system where yoiu tested your code and that worked – PDHide Dec 05 '20 at 16:45
  • Yes I removed window maximizing code. I'm still getting NoSuchElementException / Could not find element by.... errors when headless option is used. – shalinds Dec 05 '20 at 17:37
  • What window size are you setting – PDHide Dec 05 '20 at 17:39
  • Screen Size ("--window-size=1300,1000") , I took a screenshot with headless mode and I can see screen size is correct. But some test cases fail with NoSuchElementException error. Same test case pass when running without Headless mode – shalinds Dec 05 '20 at 17:47
  • Without headless mode but same screen size ? – PDHide Dec 05 '20 at 18:02
  • If so then add explicit wait for those elements , headless browser is faster than normal browser so you might need more waits for headless browser – PDHide Dec 05 '20 at 18:02
  • Updated the answer with hd screen size , see if that helps – PDHide Dec 05 '20 at 18:15
  • Without headless I'm getting small screen. With headless I'm getting correct screen size. Will it be an issue if I use Thread.Sleep() instead of explicit wait ? – shalinds Dec 06 '20 at 00:41
  • You can use thread.sleep just to see if sleep help , if it helps then change it to explicit wait as that's the better approach – PDHide Dec 06 '20 at 02:17
  • 1
    Thank you for the replies. I updated the code to use headless with explicit wait and test cases are working fine – shalinds Dec 10 '20 at 13:23
  • Can you please help me on this as well @PDHide , https://stackoverflow.com/questions/65236631/selenium-get-value-from-unicef-material-ui-currency-textfield – shalinds Dec 10 '20 at 14:40