SeleniumBase/examples/capabilities/ReadMe.md

54 lines
2.9 KiB
Markdown
Raw Normal View History

### Using Desired Capabilities
You can specify browser desired capabilities for webdriver when running SeleniumBase tests on a remote SeleniumGrid server such as [BrowserStack](https://www.browserstack.com/automate/capabilities), [Sauce Labs](https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/), or [TestingBot](https://testingbot.com/support/other/test-options).
2018-12-28 10:32:29 +08:00
Sample run commands may look like this when run from the [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder: (The browser is now specified in the capabilities file.)
```bash
2018-12-28 10:32:29 +08:00
pytest my_first_test.py --browser=remote --server=USERNAME:KEY@hub.browserstack.com --port=80 --cap_file=capabilities/sample_cap_file_BS.py
```
```bash
pytest my_first_test.py --browser=remote --server=USERNAME:KEY@ondemand.saucelabs.com --port=80 --cap_file=capabilities/sample_cap_file_SL.py
```
2018-11-25 02:50:24 +08:00
(Parameters: ``--browser=remote``, ``--server=SERVER``, ``--port=PORT``, and ``--cap_file=CAP_FILE.py``)
2018-11-22 06:53:58 +08:00
2020-01-01 06:49:33 +08:00
Here's an example desired capabilities file for BrowserStack:
2018-11-22 06:53:58 +08:00
```python
desired_cap = {
'os': 'OS X',
2020-01-01 06:49:33 +08:00
'os_version': 'High Sierra',
2018-11-22 06:53:58 +08:00
'browser': 'Chrome',
2020-01-01 06:49:33 +08:00
'browser_version': '77.0',
2018-11-22 06:53:58 +08:00
'browserstack.local': 'false',
2020-01-01 06:49:33 +08:00
'browserstack.selenium_version': '3.141.59'
2018-11-22 06:53:58 +08:00
}
```
2020-01-01 06:49:33 +08:00
Here's an example desired capabilities file for Sauce Labs:
2018-11-22 06:53:58 +08:00
```python
2020-01-01 06:49:33 +08:00
capabilities = {
'browserName': 'firefox',
'browserVersion': '70.0',
'platformName': 'macOS 10.13',
'sauce:options': {
}
}
2018-11-22 06:53:58 +08:00
```
2018-11-25 02:50:24 +08:00
(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](https://www.browserstack.com/automate/capabilities), [Sauce Labs](https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/), and [TestingBot](https://testingbot.com/support/other/test-options) by following those links to their respective websites.
2018-11-22 06:53:58 +08:00
A regex parser was built into SeleniumBase to capture all lines from the specified desired capabilities file in the following formats:
``'KEY': 'VALUE'``
``'KEY': True``
``'KEY': False``
``caps['KEY'] = "VALUE"``
``caps['KEY'] = True``
``caps['KEY'] = False``
(Each pair must be on a separate line. You can interchange single and double quotes.)
2018-11-27 12:45:46 +08:00
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.