Skip to content

Files

Latest commit

72972d2 · Nov 27, 2018

History

History

capabilities

Using Desired Capabilities

You can specify browser desired capabilities for webdriver when running SeleniumBase tests on a remote SeleniumGrid server such as BrowserStack, Sauce Labs, or TestingBot.

A sample run command may look like this when run from the SeleniumBase/examples/ folder:

pytest my_first_test.py --browser=remote --server=username:key@hub.browserstack.com --port=80 --cap_file=capabilities/sample_cap_file_BS.py

(Parameters: --browser=remote, --server=SERVER, --port=PORT, and --cap_file=CAP_FILE.py)

Here's an example desired capabilities file:

desired_cap = {
    'os': 'OS X',
    'os_version': 'Sierra',
    'browser': 'Chrome',
    'browser_version': '70.0',
    'browserstack.local': 'false',
    'browserstack.selenium_version': '3.14.0',
    'browserstack.chrome.driver': '2.43'
}

A desired capabilities file can also look like this:

caps = {}
caps['browserName'] = "chrome"
caps['platform'] = "macOS 10.12"
caps['version'] = "70.0"

(You'll notice that the browser is now being specified in the capabilities file, rather than with --browser=BROWSER)

You can generate desired capabilities for BrowserStack, Sauce Labs, and TestingBot by following those links to their respective websites.

A regex parser was built into SeleniumBase to capture all lines from the specified desired capabilities file in the following formats: 'KEY': 'VALUE' caps['KEY'] = "VALUE" (Each pair must be on a separate line. You can interchange single and double quotes.)

You can also swap --browser=remote with an actual browser, eg --browser=chrome, which will combine the default SeleniumBase desired capabilities with those that were specified in the capabilities file when using --cap_file=FILE.py. Capabilities will override other parameters, so if you set the browser to one thing and the capabilities browser to another, SeleniumBase will use the capabilities browser as the browser. You'll need default SeleniumBase desired capabilities when using a proxy server (not the same as a Selenium Grid server), when downloading files to a desired folder, for disabling some warnings on Chrome, for overriding a website's Content Security Policy on Firefox, and for other reasons.