Change desktop screen resolution with Selenium
The TestingBot Desktop VMs (Windows, macOS and Linux) all support changing the screen resolution before a test starts.
We currently support the following screen resolutions:
| Value Type | Default Value | |||||||
|---|---|---|---|---|---|---|---|---|
| string | "1280x1024" |
|
Copy
ChromeOptions options = new ChromeOptions();
options.setCapability("platformName", "WIN11");
options.setCapability("browserVersion", "latest");
options.setCapability("screen-resolution", "1920x1080");
HashMap<String, Object> tbOptions = new HashMap<>();
tbOptions.put("key", "API_KEY");
tbOptions.put("secret", "API_SECRET");
options.setCapability("tb:options", tbOptions);
Copy
from selenium.webdriver.chrome.options import Options as ChromeOptions
options = ChromeOptions()
options.set_capability('platformName', 'WIN11')
options.set_capability('browserVersion', 'latest')
options.set_capability('screen-resolution', '1920x1080')
options.set_capability('tb:options', {
'key': 'API_KEY',
'secret': 'API_SECRET'
})
Copy
const capabilities = {
platformName: 'WIN11',
browserName: 'chrome',
browserVersion: 'latest',
'screen-resolution': '1920x1080',
'tb:options': {
key: 'API_KEY',
secret: 'API_SECRET'
}
};
Copy
options = Selenium::WebDriver::Chrome::Options.new
options.add_option('platformName', 'WIN11')
options.add_option('browserVersion', 'latest')
options.add_option('screen-resolution', '1920x1080')
options.add_option('tb:options', {
'key' => 'API_KEY',
'secret' => 'API_SECRET'
})
Copy
$capabilities = [
'platformName' => 'WIN11',
'browserName' => 'chrome',
'browserVersion' => 'latest',
'screen-resolution' => '1920x1080',
'tb:options' => [
'key' => 'API_KEY',
'secret' => 'API_SECRET'
]
];
Copy
ChromeOptions options = new ChromeOptions();
options.PlatformName = "WIN11";
options.BrowserVersion = "latest";
options.AddAdditionalOption("screen-resolution", "1920x1080");
var tbOptions = new Dictionary<string, object>
{
["key"] = "API_KEY",
["secret"] = "API_SECRET"
};
options.AddAdditionalOption("tb:options", tbOptions);
The browser window is not maximized when starting a Selenium test. Changing the screen resolution does not maximize the browser.
See how to maximize and resize the browser window.