14

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
  • In what way is it not working? Commented Sep 3, 2013 at 16:23

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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));

1 Comment

The website I'm testing is responsive. The markup changes from large to small breakpoints.
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.

2 Comments

But they mentioned, we can modify/adjust the screen-resolution on Windows, Linux and Mac..? link.
Poor choice of words on their part I'm afraid.
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. =)

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.