15

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");
Srikanth Nakka
  • 758
  • 4
  • 16
  • 35

4 Answers4

27

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.

Ardesco
  • 7,281
  • 26
  • 49
6

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));
JacekM
  • 4,041
  • 1
  • 27
  • 34
  • 1
    The website I'm testing is [responsive](https://en.wikipedia.org/wiki/Responsive_web_design). The markup changes from large to small breakpoints. – Dave Teply Jun 02 '17 at 20:31
2

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.

Dingredient
  • 2,191
  • 22
  • 47
  • But they mentioned, we can modify/adjust the screen-resolution on Windows, Linux and Mac..? [link](http://blog.testingbot.com/2013/03/15/screen-resolution-option-now-available-for-all-selenium-tests). – Srikanth Nakka Sep 03 '13 at 16:34
  • 1
    Poor choice of words on their part I'm afraid. – Dingredient Sep 03 '13 at 16:34
0

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. =)

Community
  • 1
  • 1
Stephen B.
  • 204
  • 2
  • 9
  • 2
    We just ran into the same problem in our test automation infrastructure. The problem is Windows defaults to a very small screen size(I assume 800x600), and then if the website under test doesn't support such a small resolution without overlapping UI elements, and the browser will fail some tests for items that are no longer visible. – Cristian Măgherușan-Stanciu Feb 29 '16 at 15:31