简体   繁体   中英

Test failed on different monitor selenium webdriver java

I am working at selenium webdriver with java. i have 2 screens in my office and i had set a fixed window dimension for chrome browser as

driver.manage().window().setSize(new Dimension(1680, 1050));

when i execute code in office mean when i am connected with 2 screens every test case work fine both on laptop and second connected LED but when i remove second screen and work only at my laptop then test cases start failing.

Note: above window size is greater than laptop screen but less than LED size

I searched a lot to find a solution but failed. Looking for solution to execute test case even when i am not connected with an external LED. Help will be appreciated. Many Thanks

You can avoid hard coded value to check the window size first and then Assigned it based on screen size.

  WebDriver driver = new ChromeDriver();
  driver.manage().window().maximize();
  System.out.println(driver.manage().window().getSize());
  driver.manage().window().setSize(driver.manage().window().getSize());

See if it helps.

In general when dealing with different screen resolution, we need to strict with resolution of all execution slaves. Say example,

driver.manage().window().setSize(new Dimension(1920, 1080));

Or else we need to use JS scroll into view for all the commands to pass the cases for different resolution( but, not recommended considering performance).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM