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
Copy file name to clipboardExpand all lines: help_docs/customizing_test_runs.md
+63-59Lines changed: 63 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,17 @@ In addition to [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/m
7
7
The following tests can be run from the [examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder:
8
8
9
9
```bash
10
-
# Run my_first_test.py in Chrome (default browser)
11
-
pytest my_first_test.py
10
+
# Run a test in Chrome (default browser)
11
+
pytest test_swag_labs.py
12
12
13
-
# Run my_first_test.py in Firefox
14
-
pytest my_first_test.py --browser=firefox
13
+
# Run a test in Firefox
14
+
pytest test_swag_labs.py --browser=firefox
15
15
16
16
# Run a test in Demo Mode (highlight assertions)
17
-
pytest my_first_test.py --demo
17
+
pytest test_swag_labs.py --demo
18
18
19
19
# Run a test in Headless Mode (invisible browser)
20
-
pytest my_first_test.py --headless
20
+
pytest test_swag_labs.py --headless
21
21
22
22
# Run tests multi-threaded using [n] threads
23
23
pytest test_suite.py -n=4
@@ -69,6 +69,63 @@ You can interchange **pytest** with **nosetests** for most things, but using pyt
69
69
70
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).)
71
71
72
+
Here are some useful command-line options that come with Pytest:
73
+
```bash
74
+
-v # Prints the full test name for each test.
75
+
-q # Prints fewer details in the console output when running tests.
76
+
-x # Stop running the tests after the first failure is reached.
77
+
--html=report.html # Creates a detailed test report after tests complete. (Using the pytest-html plugin)
78
+
--collect-only # Show what tests would get run without actually running them.
79
+
-s # See print statements. (Should be on by default with pytest.ini present.)
80
+
-n=NUM # Multithread the tests using that many threads. (Speed up test runs!)
81
+
```
82
+
83
+
SeleniumBase provides additional Pytest command-line options for tests:
84
+
```bash
85
+
--browser=BROWSER # (The web browser to use.)
86
+
--cap-file=FILE # (The web browser's desired capabilities to use.)
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
89
+
--data=DATA # (Extra data to pass to tests. Use "self.data" in tests.)
90
+
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
91
+
--server=SERVER # (The server / IP address used by the tests.)
92
+
--port=PORT # (The port that's used by the test server.)
93
+
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
94
+
--agent=STRING # (This designates the web browser's User Agent to use.)
95
+
--mobile # (The option to use the mobile emulator while running tests.)
96
+
--metrics=STRING # ("CSSWidth,Height,PixelRatio" for mobile emulator tests.)
97
+
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
98
+
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
99
+
--headless # (The option to run tests headlessly. The default on Linux OS.)
100
+
--headed # (The option to run tests with a GUI on Linux OS.)
101
+
--start-page=URL # (The starting URL for the web browser when tests begin.)
102
+
--archive-logs # (Archive old log files instead of deleting them.)
103
+
--time-limit # (The option to set a time limit per test before failing it.)
104
+
--slow # (The option to slow down the automation.)
105
+
--demo # (The option to visually see test actions as they occur.)
106
+
--demo-sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
107
+
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
108
+
--message-duration=SECONDS # (The time length for Messenger alerts.)
109
+
--check-js # (The option to check for JavaScript errors after page loads.)
110
+
--ad-block # (The option to block some display ads after page loads.)
111
+
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
112
+
--disable-csp # (This disables the Content Security Policy of websites.)
113
+
--enable-sync # (The option to enable "Chrome Sync".)
114
+
--no-sandbox # (The option to enable Chrome's "No-Sandbox" feature.)
115
+
--disable-gpu # (The option to enable Chrome's "Disable GPU" feature.)
116
+
--incognito # (The option to enable Chrome's Incognito mode.)
117
+
--guest # (The option to enable Chrome's Guest mode.)
118
+
--devtools # (The option to open Chrome's DevTools when the browser opens.)
119
+
--reuse-session # (The option to reuse the browser session between tests.)
120
+
--maximize-window # (The option to start with the web browser maximized.)
121
+
--save-screenshot # (The option to save a screenshot after each test.)
122
+
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
123
+
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
124
+
```
125
+
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
126
+
127
+
#### **Customizing default settings:**
128
+
72
129
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.
73
130
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))
(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.)
180
237
181
-
Here are some other useful command-line options that come with Pytest:
182
-
```bash
183
-
-v # Prints the full test name for each test.
184
-
-q # Prints fewer details in the console output when running tests.
185
-
-x # Stop running the tests after the first failure is reached.
186
-
--html=report.html # Creates a detailed test report after tests complete. (Using the pytest-html plugin)
187
-
--collect-only # Show what tests would get run without actually running them.
188
-
-s # See print statements. (Should be on by default with pytest.ini present.)
189
-
-n=NUM # Multithread the tests using that many threads. (Speed up test runs!)
190
-
```
191
-
192
-
SeleniumBase provides additional Pytest command-line options for tests:
193
-
```bash
194
-
--browser=BROWSER # (The web browser to use.)
195
-
--cap-file=FILE # (The web browser's desired capabilities to use.)
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
198
-
--data=DATA # (Extra data to pass to tests. Use "self.data" in tests.)
199
-
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
200
-
--server=SERVER # (The server / IP address used by the tests.)
201
-
--port=PORT # (The port that's used by the test server.)
202
-
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
203
-
--agent=STRING # (This designates the web browser's User Agent to use.)
204
-
--mobile # (The option to use the mobile emulator while running tests.)
205
-
--metrics=STRING # ("CSSWidth,Height,PixelRatio" for mobile emulator tests.)
206
-
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
207
-
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
208
-
--headless # (The option to run tests headlessly. The default on Linux OS.)
209
-
--headed # (The option to run tests with a GUI on Linux OS.)
210
-
--start-page=URL # (The starting URL for the web browser when tests begin.)
211
-
--archive-logs # (Archive old log files instead of deleting them.)
212
-
--time-limit # (The option to set a time limit per test before failing it.)
213
-
--slow # (The option to slow down the automation.)
214
-
--demo # (The option to visually see test actions as they occur.)
215
-
--demo-sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
216
-
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
217
-
--message-duration=SECONDS # (The time length for Messenger alerts.)
218
-
--check-js # (The option to check for JavaScript errors after page loads.)
219
-
--ad-block # (The option to block some display ads after page loads.)
220
-
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
221
-
--disable-csp # (This disables the Content Security Policy of websites.)
222
-
--enable-sync # (The option to enable "Chrome Sync".)
223
-
--no-sandbox # (The option to enable Chrome's "No-Sandbox" feature.)
224
-
--disable-gpu # (The option to enable Chrome's "Disable GPU" feature.)
225
-
--incognito # (The option to enable Chrome's Incognito mode.)
226
-
--reuse-session # (The option to reuse the browser session between tests.)
227
-
--maximize-window # (The option to start with the web browser maximized.)
228
-
--save-screenshot # (The option to save a screenshot after each test.)
229
-
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
230
-
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
231
-
```
232
-
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
233
-
234
238
#### **Using a Proxy Server:**
235
239
236
240
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.
0 commit comments