In certain test scenarios, you might want to run browser tests with different screen resolutions than those offered on the Sauce Labs cloud by using the screen resolution desired capability. This enables you to programmatically re-size the browser window using Selenium WebDriver during a test's execution before the commands of the test execute. This article includes examples of how to re-size screen resolutions in several programming languages.
Maximum Resolutions If you set the resolution greater than the default resolution, or the |
Java
Dimension dim = new Dimension(width,height) driver.manage().window().setSize(dim) |
Required Java Library You need to import the library |
Python
driver.set_window_size(width, height) |
C#
driver.Manage().Window.Size = new Size(x, y); |
Required Namespace You need to include the |
JavaScript
selenium-webdriver
driver.manage().window().setSize(x, y); |
WebDriverIO
browser.setViewPortSize({ width: x, height: y }); |
To learn more about changing the window size, check out this blog post and this StackOverflow question.