Specifying custom screen resolution in Selenium tests

人走茶凉 提交于 2020-01-02 01:16:52

问题


As mentioned in the below blog, we can modify screen resolution during selenium test runs. http://blog.testingbot.com/2013/03/15/screen-resolution-option-now-available-for-all-selenium-tests

Tried the below code(as mentioned in "https://saucelabs.com/docs/additional-config"), but not setting the specified resolution. Is this still not available for Selenium?

DesiredCapabilities dc=new DesiredCapabilities();    
dc.setCapability("screen-resolution","1280x1024");

回答1:


Sauce Labs != Selenium

Sauce labs use that capability to provision you a VM with the desired resolution, it's not a capability that Selenium itself knows about.

Selenium is not capable of modifying your desktop resolution!

If you want to modify your browser size in Selenium so that it matches a specific resolution you can do a:

driver.manage().window().setSize(new Dimension(1024, 768))

The above is not supported with Opera driver, so instead you would need to do:

DesiredCapabilities capabilities = DesiredCapabilities.opera()
capabilities.setCapability("opera.arguments", "-screenwidth 1024 -screenheight 768")

While setting the browser size is not the same as setting the screen resolution, it should for all intents and purposes meet your requirements.




回答2:


Selenium is a browser automation framework, its job is to drive a browser, not to automate your system. I don't think that a functionality such as setting a screen resolution will ever be implemented in Selenium. Setting resolution has simply nothing to do with browser automation.

I am not sure why do you want to change the resolution... How about just changing the size of your browser window? That's something you could do if you are testing responsive-designed pages.

driver.manage().window().setSize(new Dimension(800, 600));



回答3:


The purpose of DesiredCapabilities is to tell the Grid where to run your tests.

So, if there is a remote node connected to the Grid with the resolution you specified 1280x1024, the test will run on that node. If any other nodes do not have this resolution, the test will not run on those nodes.

If you do not specify a screen resolution in the DesiredCapabilities, the test will run on nodes with any resolution.

This feature of Selenium does not actually change or modify a testing node's screen resolution. It only tells the Grid on which nodes to run or not run your tests.




回答4:


What you are interested in doing is probably best done through native java code rather than through Selenium which is a web browser testing framework.

The question of changing the resolution through Java was addressed in another thread here on StackOverflow.

swing - Change screen resolution in Java

Although I am curious as to why you are trying to do this, since you didn't explain that above and may lead to a better response from the community. =)



来源:https://stackoverflow.com/questions/18596732/specifying-custom-screen-resolution-in-selenium-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!