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
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
209
209
--data=DATA # (Extra data to pass to tests. Use "self.data" in tests.)
210
-
--user_data_dir=DIR # (Set the Chrome user data directory to use.)
210
+
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
211
211
--server=SERVER # (The server / IP address used by the tests.)
212
212
--port=PORT # (The port that's used by the test server.)
213
213
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
214
214
--agent=STRING # (This designates the web browser's User Agent to use.)
215
-
--extension_zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
216
-
--extension_dir=DIR # (Load a Chrome Extension directory, comma-separated.)
215
+
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
216
+
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
217
217
--headless # (The option to run tests headlessly. The default on Linux OS.)
218
218
--headed # (The option to run tests with a GUI on Linux OS.)
219
-
--start_page=URL # (The starting URL for the web browser when tests begin.)
220
-
--log_path=LOG_PATH # (The directory where log files get saved to.)
221
-
--archive_logs# (Archive old log files instead of deleting them.)
219
+
--start-page=URL # (The starting URL for the web browser when tests begin.)
220
+
--log-path=LOG_PATH # (The directory where log files get saved to.)
221
+
--archive-logs# (Archive old log files instead of deleting them.)
222
222
--slow # (The option to slow down the automation.)
223
223
--demo # (The option to visually see test actions as they occur.)
224
-
--demo_sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
224
+
--demo-sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
225
225
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
226
-
--message_duration=SECONDS # (The time length for Messenger alerts.)
227
-
--check_js # (The option to check for JavaScript errors after page loads.)
228
-
--ad_block # (The option to block some display ads after page loads.)
229
-
--verify_delay=SECONDS # (The delay before MasterQA verification checks.)
230
-
--disable_csp # (This disables the Content Security Policy of websites.)
231
-
--enable_sync # (The option to enable "Chrome Sync".)
232
-
--maximize_window # (The option to start with the web browser maximized.)
233
-
--save_screenshot # (The option to save a screenshot after each test.)
234
-
--visual_baseline # (Set the visual baseline for Visual/Layout tests.)
235
-
--timeout_multiplier=MULTIPLIER # (Multiplies the default timeout values.)
226
+
--message-duration=SECONDS # (The time length for Messenger alerts.)
227
+
--check-js # (The option to check for JavaScript errors after page loads.)
228
+
--ad-block # (The option to block some display ads after page loads.)
229
+
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
230
+
--disable-csp # (This disables the Content Security Policy of websites.)
231
+
--enable-sync # (The option to enable "Chrome Sync".)
232
+
--reuse-session # (The option to reuse the browser session between tests.)
233
+
--maximize-window # (The option to start with the web browser maximized.)
234
+
--save-screenshot # (The option to save a screenshot after each test.)
235
+
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
236
+
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
236
237
```
237
238
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
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.
@@ -62,7 +66,7 @@ You can interchange **pytest** with **nosetests**, but using pytest is strongly
62
66
63
67
An easy way to override seleniumbase/config/settings.py is by using a custom settings file.
64
68
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))
65
-
``--settings_file=custom_settings.py``
69
+
``--settings-file=custom_settings.py``
66
70
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, and other important settings used by tests.)
67
71
68
72
#### **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, (or your own):**
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_mode`` 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:
110
+
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:
You can override the default wait time by either updating [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) or by using ``--demo_sleep={NUM}`` when using Demo Mode. (NOTE: If you use ``--demo_sleep={NUM}`` without using ``--demo_mode``, nothing will happen.)
116
+
You can override the default wait time by either updating [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) or by using ``--demo-sleep={NUM}`` when using Demo Mode. (NOTE: If you use ``--demo-sleep={NUM}`` without using ``--demo``, nothing will happen.)
@@ -125,24 +129,24 @@ To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or
125
129
126
130
#### **Retrying failing tests automatically:**
127
131
128
-
You can use ``--rerunsNUM`` to retry failing tests that many times. Use ``--reruns-delaySECONDS`` to wait that many seconds between retries. Example:
132
+
You can use ``--reruns=NUM`` to retry failing tests that many times. Use ``--reruns-delay=SECONDS`` to wait that many seconds between retries. Example:
129
133
```
130
-
pytest --reruns 5 --reruns-delay1
134
+
pytest --reruns=2 --reruns-delay=1
131
135
```
132
136
133
137
#### **Debugging tests:**
134
138
135
139
**You can use the following code snippets in your scripts to help you debug issues:**
136
140
```python
137
-
import time; time.sleep(5) #sleep for 5 seconds (add this after the line you want to pause on)
138
-
import ipdb; ipdb.set_trace() #waits for your command. n = next line of current method, c = continue, s = step / next executed line (will jump)
139
-
import pytest; pytest.set_trace() #similar to ipdb, but specific to pytest
141
+
import time; time.sleep(5) #Makes the test wait and do nothing for 5 seconds.
142
+
import ipdb; ipdb.set_trace() #Enter debugging mode. n = next, c = continue, s = step.
143
+
import pytest; pytest.set_trace() #Enter debugging mode. n = next, c = continue, s = step.
140
144
```
141
145
142
146
**To pause an active test that throws an exception or error, add ``--pdb -s``:**
143
147
144
148
```bash
145
-
pytest my_first_test.py --browser=chrome --pdb -s
149
+
pytest my_first_test.py --pdb -s
146
150
```
147
151
148
152
The code above will leave your browser window open in case there's a failure. (ipdb commands: 'c', 's', 'n' => continue, step, next).
@@ -181,36 +185,37 @@ Here are some other useful command-line options that come with Pytest:
181
185
SeleniumBase provides additional Pytest command-line options for tests:
182
186
```bash
183
187
--browser=BROWSER # (The web browser to use.)
184
-
--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.)
187
191
--data=DATA # (Extra data to pass to tests. Use "self.data" in tests.)
188
-
--user_data_dir=DIR # (Set the Chrome user data directory to use.)
192
+
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
189
193
--server=SERVER # (The server / IP address used by the tests.)
190
194
--port=PORT # (The port that's used by the test server.)
191
195
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
192
196
--agent=STRING # (This designates the web browser's User Agent to use.)
193
-
--extension_zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
194
-
--extension_dir=DIR # (Load a Chrome Extension directory, comma-separated.)
197
+
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
198
+
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
195
199
--headless # (The option to run tests headlessly. The default on Linux OS.)
196
200
--headed # (The option to run tests with a GUI on Linux OS.)
197
-
--start_page=URL # (The starting URL for the web browser when tests begin.)
198
-
--log_path=LOG_PATH # (The directory where log files get saved to.)
199
-
--archive_logs# (Archive old log files instead of deleting them.)
201
+
--start-page=URL # (The starting URL for the web browser when tests begin.)
202
+
--log-path=LOG_PATH # (The directory where log files get saved to.)
203
+
--archive-logs# (Archive old log files instead of deleting them.)
200
204
--slow # (The option to slow down the automation.)
201
205
--demo # (The option to visually see test actions as they occur.)
202
-
--demo_sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
206
+
--demo-sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
203
207
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
204
-
--message_duration=SECONDS # (The time length for Messenger alerts.)
205
-
--check_js # (The option to check for JavaScript errors after page loads.)
206
-
--ad_block # (The option to block some display ads after page loads.)
207
-
--verify_delay=SECONDS # (The delay before MasterQA verification checks.)
208
-
--disable_csp # (This disables the Content Security Policy of websites.)
209
-
--enable_sync # (The option to enable "Chrome Sync".)
210
-
--maximize_window # (The option to start with the web browser maximized.)
211
-
--save_screenshot # (The option to save a screenshot after each test.)
212
-
--visual_baseline # (Set the visual baseline for Visual/Layout tests.)
213
-
--timeout_multiplier=MULTIPLIER # (Multiplies the default timeout values.)
208
+
--message-duration=SECONDS # (The time length for Messenger alerts.)
209
+
--check-js # (The option to check for JavaScript errors after page loads.)
210
+
--ad-block # (The option to block some display ads after page loads.)
211
+
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
212
+
--disable-csp # (This disables the Content Security Policy of websites.)
213
+
--enable-sync # (The option to enable "Chrome Sync".)
214
+
--reuse-session # (The option to reuse the browser session between tests.)
215
+
--maximize-window # (The option to start with the web browser maximized.)
216
+
--save-screenshot # (The option to save a screenshot after each test.)
217
+
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
218
+
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
214
219
```
215
220
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
If you wish to change the User-Agent for your browser tests (Chrome and Firefox only), you can add ``--agent="USER-AGENTSTRING"`` as an argument on the command line.
244
+
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.
0 commit comments