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.
driver.Manage().Window.Size = new Size(x, y);
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("resolution", "1920x1080");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--window-size=1300,1000");
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
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
I tried the solution which you have given but test cases fail with NoSuchElementException erros. Thank You !
@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
Yes I removed window maximizing code. I'm still getting NoSuchElementException / Could not find element by.... errors when headless option is used.
What window size are you setting
Thank you for the replies. I updated the code to use headless with explicit wait and test cases are working fine