简体   繁体   English

测试在不同的监视器Selenium WebDriver Java上失败

[英]Test failed on different monitor selenium webdriver java

I am working at selenium webdriver with java. 我正在使用Java硒网络驱动程序。 i have 2 screens in my office and i had set a fixed window dimension for chrome browser as 我在办公室中有2个屏幕,并且为chrome浏览器设置了一个固定的窗口尺寸

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. 当我在办公室执行代码时,意味着当我用2个屏幕连接时,每个测试用例在笔记本电脑和第二个连接的LED上都可以正常工作,但是当我卸下第二个屏幕并仅在笔记本电脑上工作时,测试用例就会开始失败。

Note: above window size is greater than laptop screen but less than LED size 注意:以上窗口大小大于笔记本电脑屏幕,但小于LED大小

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. 寻找解决方案以执行测试用例,即使我未与外部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)); 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). 否则,我们需要对所有命令使用JS滚动视图,以传递不同分辨率的案例(但不建议考虑性能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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