Srikanth Nakka Srikanth Nakka - 1 year ago 632
Java Question

Specifying custom screen resolution in Selenium tests

In the below blog they mentioned, we can modify screen resolution during selenium test runs.

I have tried the below code(as mentioned in ""), but not setting the specified resolution. Is this still not available for Selenium? Please someone help me.

DesiredCapabilities dc=new DesiredCapabilities();

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download