Srikanth Nakka
Srikanth Nakka

Reputation: 758

Specifying custom screen resolution in Selenium tests

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

Upvotes: 14

Views: 61394

Answers (4)

Ardesco
Ardesco

Reputation: 7441

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.

Upvotes: 26

JacekM
JacekM

Reputation: 4099

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

Upvotes: 6

Stephen B.
Stephen B.

Reputation: 204

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

Upvotes: 0

Dingredient
Dingredient

Reputation: 2199

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.

Upvotes: 2

Related Questions