You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## <imgsrc="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3.png"title="SeleniumBase"height="32"> Running Example Tests:
3
+
## <imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Running Example Tests:
4
4
5
5
SeleniumBase tests are run with **``pytest``**. Chrome is the default browser if not specifed. During test failures, logs and screenshots from the latest run are saved to the ``latest_logs/`` folder.
### <imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Logging, Screenshots, and Reports:
2
4
3
5
Log files in [SeleniumBase/examples/example_logs](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/example_logs) were generated when [test_fail.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_fail.py) ran and failed. During test failures, logs and screenshots get saved to the ``latest_logs/`` folder. If ``--archive-logs`` is set, test logs will get archived to the ``archived_logs/`` folder.
The ``--report`` option gives you a fancy report after your test suite completes. (Requires ``--with-testing_base`` to also be set when ``--report`` is used because it's part of that plugin.)
(NOTE: You can add ``--show_report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show_report`` when running tests locally because it pauses the test run.)
44
+
(NOTE: You can add ``--show_report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show_report`` when running tests locally because it pauses the test run.)
## <imgsrc="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3.png"title="SeleniumBase"height="32"> Customizing test runs
3
+
## <imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Customizing test runs
4
4
5
5
You can customize test runs from the command-line thanks to [SeleniumBase's pytest plugin](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py), which adds command-line options for setting/enabling the browser type, headless mode, mobile mode, multithreading mode, demo mode, proxy config, user agent config, browser extensions, and more.
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
An easy way to override [seleniumbase/config/settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) is by using a custom settings file.
140
140
Here's the command-line option to add to tests: (See [examples/custom_settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/custom_settings.py))
141
141
``--settings-file=custom_settings.py``
142
142
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, and other important settings used by tests.)
143
143
144
-
#### **Running tests on [BrowserStack](https://www.browserstack.com/automate#)'s Selenium Grid, the [Sauce Labs](https://saucelabs.com/products/open-source-frameworks/selenium) Selenium Grid, the [TestingBot](https://testingbot.com/features) Selenium Grid, another grid, or your own:**
144
+
### <imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Running tests on a remote Selenium Grid:
145
+
146
+
SeleniumBase lets you run tests on remote Selenium Grids such as [BrowserStack](https://www.browserstack.com/automate#)'s Selenium Grid, [Sauce Labs](https://saucelabs.com/products/open-source-frameworks/selenium)'s Selenium Grid, [TestingBot](https://testingbot.com/features)'s Selenium Grid, other Grids, and even your own Grid:
145
147
146
148
(For setting browser desired capabilities while running Selenium remotely, see the ReadMe located here: https://github.com/seleniumbase/SeleniumBase/tree/master/examples/capabilities)
Or you can create your own Selenium Grid for test distribution. ([See this ReadMe for details](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_grid/ReadMe.md))
174
176
175
-
#### **Example tests using Logging:**
177
+
###<imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Example tests using Logging:
176
178
177
179
```bash
178
180
pytest test_suite.py --browser=chrome
179
181
```
180
182
(During test failures, logs and screenshots from the most recent test run will get saved to the ``latest_logs/`` folder. Those logs will get moved to ``archived_logs/`` if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), otherwise log files with be cleaned up at the start of the next test run.)
If any test is moving too fast for your eyes to see what's going on, you can run it in **Demo Mode** by adding ``--demo`` on the command line, which pauses the browser briefly between actions, highlights page elements being acted on, and lets you know what test assertions are happening in real time:
185
187
@@ -193,22 +195,22 @@ You can override the default wait time by either updating [settings.py](https://
193
195
pytest my_first_test.py --demo --demo-sleep=1.2
194
196
```
195
197
196
-
#### **Passing additional data to tests:**
198
+
###<imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Passing additional data to tests:
197
199
198
200
If you want to pass additional data from the command line to your tests, you can use ``--data=STRING``. Now inside your tests, you can use ``self.data`` to access that.
To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or ``-n NUM`` on the command line, where NUM is the number of CPUs you want to use.
You can use ``--reruns=NUM`` to retry failing tests that many times. Use ``--reruns-delay=SECONDS`` to wait that many seconds between retries. Example:
(NOTE: You can add ``--show_report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show_report`` when running tests locally because it pauses the test run.)
247
249
248
-
#### **Using a Proxy Server:**
250
+
###<imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Using a Proxy Server:
249
251
250
252
If you wish to use a proxy server for your browser tests (Chrome and Firefox only), you can add ``--proxy=IP_ADDRESS:PORT`` as an argument on the command line.
251
253
@@ -265,15 +267,15 @@ To make things easier, you can add your frequently-used proxies to PROXY_LIST in
265
267
pytest proxy_test.py --proxy=proxy1
266
268
```
267
269
268
-
#### **Changing the User-Agent:**
270
+
###<imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Changing the User-Agent:
269
271
270
272
If you wish to change the User-Agent for your browser tests (Chrome and Firefox only), you can add ``--agent="USER-AGENT-STRING"`` as an argument on the command line.
###<imgsrc="https://seleniumbase.io/img/sb_icon.png"title="SeleniumBase"height="30" /> Mobile Device Testing:
277
279
278
280
Use ``--mobile`` to quickly run your tests using Chrome's mobile device emulator with default values for device metrics (CSS Width, CSS Height, Pixel-Ratio) and a default value set for the user agent. To configure the mobile device metrics, use ``--metrics="CSS_Width,CSS_Height,Pixel_Ratio"`` to set those values. You'll also be able to set the user agent with ``--agent="USER-AGENT-STRING"`` (a default user agent will be used if not specified). To find real values for device metrics, [see this GitHub Gist](https://gist.github.com/sidferreira/3f5fad525e99b395d8bd882ee0fd9d00). For a list of available user agent strings, [check out this page](https://developers.whatismybrowser.com/useragents/explore/).
Here's a summary of SeleniumBase method definitions, which are defined in [base_case.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py)
SeleniumBase console scripts help you get things done more easily, such as installing web drivers, creating a test directory with necessary configuration files, converting old WebDriver unittest scripts into SeleniumBase code, translating tests into multiple languages, and using the Selenium Grid.
* You need a different webdriver for each web browser you want to run automation on: ``chromedriver`` for Chrome, ``edgedriver`` for Edge, ``geckodriver`` for Firefox, ``operadriver`` for Opera, and ``iedriver`` for Internet Explorer.
0 commit comments