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
All-in-one framework for web automation, end-to-end testing, and website tours. SeleniumBase uses pytest for running Python scripts, while using Selenium WebDriver for controlling web browsers.
5
+
All-in-one framework for web automation, end-to-end testing, and website tours. SeleniumBase uses [pytest](https://pytest.org) for running Python scripts, while using [Selenium WebDriver](https://selenium.dev/) for controlling web browsers.
6
6
7
-
* Contains reliable, smart-waiting code to prevent flaky tests.
8
-
* Simplifies the process of creating UI tests for any website.
9
-
* Includes [Plugins](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py) for logging [test results and screenshots](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md).
10
-
* Multiplies the abilities of [pytest](https://pytest.org) and [Selenium WebDriver](https://selenium.dev/).
11
-
* Uses versatile [Python methods](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md) and [command-line options](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md).
7
+
* Helps you build reliable, non-flaky UI tests for any website.
8
+
* Includes flexible [command-line options](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md) for running tests.
9
+
* Comes with easy-to-use [Python methods](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md) for writing tests.
12
10
* Includes tools for [assisted-QA](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/master_qa/ReadMe.md), [visual testing](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/visual_testing/ReadMe.md), and [web tours](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md).
13
-
* Integrates with [Selenium Grid](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_grid/ReadMe.md), [Katalon Recorder](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_ide/ReadMe.md), and [MySQL](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/core/testcase_manager.py).
14
-
* Supports [Azure Pipelines](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/azure/azure_pipelines/ReadMe.md), [GCP](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/google_cloud/ReadMe.md), [TravisCI](https://github.com/seleniumbase/SeleniumBase/blob/master/.travis.yml), [Docker](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/docker/ReadMe.md), and more.
11
+
* Integrates with [Selenium Grid](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_grid/ReadMe.md), [Katalon Recorder](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_ide/ReadMe.md), and more.
15
12
* To see the full list of SeleniumBase features, [click here](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/features_list.md).
Copy file name to clipboardExpand all lines: help_docs/customizing_test_runs.md
+57-35Lines changed: 57 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,69 +2,74 @@
2
2
3
3
## <imgsrc="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png"title="SeleniumBase"height="32"> Customizing test runs
4
4
5
-
In addition to [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) (which lets you customize SeleniumBase global properties) you can customize test runs from the command line with pytest (or nosetests):
6
-
7
-
* Choose the browser for tests to use (Default: Chrome)
8
-
* Choose betweeen pytest & nose unittest runners
9
-
* Choose whether to enter Debug Mode on failures
10
-
* Choose additional variables to pass into tests
11
-
* Choose the User-Agent for the browser to use
12
-
* Choose the automation speed (with Demo Mode)
13
-
* Choose whether to run tests multi-threaded
14
-
* Choose whether to rerun failing tests
15
-
* Choose whether to reuse the browser session
16
-
* Choose a Chrome Extension to load
17
-
* Choose a Chrome User Data Directory to use
18
-
* Choose a BrowserStack server to run on
19
-
* Choose a Sauce Labs server to run on
20
-
* Choose a TestingBot server to run on
21
-
* Choose a CrossBrowserTesting server
22
-
* Choose a Selenium Grid to connect to
23
-
* Choose a database to save results to
24
-
* Choose a proxy server to connect to
25
-
26
-
...and more!
27
-
28
-
#### **Examples:**
29
-
30
-
These are run from the **[examples](https://github.com/seleniumbase/SeleniumBase/tree/master/examples)** folder.
31
-
(Chrome is the default browser if not specified.)
5
+
In addition to [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) for customizing global properties, you can customize test runs [from the command-line](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py).
6
+
7
+
The following tests can be run from the [examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder:
32
8
33
9
```bash
10
+
# Run my_first_test.py in Chrome (default browser)
34
11
pytest my_first_test.py
35
12
13
+
# Run my_first_test.py in Firefox
14
+
pytest my_first_test.py --browser=firefox
15
+
16
+
# Run tests in Demo Mode to see assertions
36
17
pytest my_first_test.py --demo
37
18
38
-
pytest my_first_test.py --browser=firefox
19
+
# Run tests in Headless Mode (invisible browser)
20
+
pytest test_suite.py --headless
21
+
22
+
# Run tests multi-threaded using [n] threads
23
+
pytest test_suite.py -n=4
39
24
25
+
# Create a pytest html report after tests are done
40
26
pytest test_suite.py --html=report.html
41
27
42
-
nosetests test_suite.py --report --show-report
28
+
# Enter Debug Mode on failures
29
+
pytest test_fail.py --pdb -s
30
+
31
+
# Rerun failing tests more times
32
+
pytest test_suite.py --reruns=1
43
33
44
-
pytest test_suite.py --headless -n=4
34
+
# Pass extra data into tests (retrieve: self.data)
You can interchange **pytest** with **nosetests**, but using pytest is strongly recommended because developers stopped supporting nosetests. Chrome is the default browser if not specified.
68
+
You can interchange **pytest** with **nosetests** for most things, but using pytest is strongly recommended because developers stopped supporting nosetests. Chrome is the default browser if not specified.
64
69
65
70
(NOTE: If you're using **pytest** for running tests outside of the SeleniumBase repo, **you'll want a copy of [pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini) at the base of the new folder structure**. If using **nosetests**, the same applies for [setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg).)
66
71
67
-
An easy way to override seleniumbase/config/settings.py is by using a custom settings file.
72
+
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.
68
73
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))
69
74
``--settings-file=custom_settings.py``
70
75
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, and other important settings used by tests.)
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/).
260
+
261
+
```bash
262
+
# Run tests using Chrome's mobile device emulator (default settings)
263
+
pytest test_swag_labs.py --mobile
264
+
265
+
# Run mobile tests specifying CSS Width, CSS Height, and Pixel-Ratio
0 commit comments