Skip to content

Commit 3a26df6

Browse files
committed
Refactoring command line options and docs
1 parent c1907a0 commit 3a26df6

File tree

3 files changed

+96
-76
lines changed

3 files changed

+96
-76
lines changed

help_docs/customizing_test_runs.md

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ pytest test_swag_labs.py
1414
pytest test_swag_labs.py --browser=firefox
1515

1616
# Run a test in Demo Mode (highlight assertions)
17-
pytest test_swag_labs.py --demo
17+
pytest my_first_test.py --demo
18+
19+
# Run another test in Demo Mode
20+
pytest test_demo_site.py --demo
1821

1922
# Run a test in Headless Mode (invisible browser)
20-
pytest test_swag_labs.py --headless
23+
pytest my_first_test.py --headless
2124

2225
# Run tests multi-threaded using [n] threads
2326
pytest test_suite.py -n=4
@@ -26,12 +29,12 @@ pytest test_suite.py -n=4
2629
pytest test_suite.py --html=report.html
2730

2831
# Enter Debug Mode on failures
29-
pytest test_fail.py --pdb -s
32+
pytest test_fail.py --pdb
3033

3134
# Rerun failing tests more times
3235
pytest test_suite.py --reruns=1
3336

34-
# Pass extra data into tests (retrieve: self.data)
37+
# Pass extra data into tests (retrieve by calling self.data)
3538
pytest my_first_test.py --data="ABC,DEF"
3639

3740
# Run tests on a local Selenium Grid
@@ -68,14 +71,15 @@ pytest test_swag_labs.py --mobile --metrics="411,731,3"
6871
pytest my_first_test.py --settings-file=custom_settings.py
6972
```
7073

71-
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.
74+
You can interchange ``pytest`` with ``nosetests`` for most tests, but using ``pytest`` is recommended. (``chrome`` is the default browser if not specified.)
7275

73-
(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).)
76+
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).
77+
78+
Here are some useful command-line options that come with ``pytest``:
7479

75-
Here are some useful command-line options that come with Pytest:
7680
```bash
77-
-v # Prints the full test name for each test.
78-
-q # Prints fewer details in the console output when running tests.
81+
-v # Verbose mode. Print the full name of each test run.
82+
-q # Quiet mode. Print fewer details in the console output when running tests.
7983
-x # Stop running the tests after the first failure is reached.
8084
--html=report.html # Creates a detailed pytest-html report after tests finish.
8185
--collect-only # Show what tests would get run without actually running them.
@@ -86,56 +90,70 @@ Here are some useful command-line options that come with Pytest:
8690
-m=MARKER # Only run tests that are marked with the specified pytest marker.
8791
```
8892

89-
SeleniumBase provides additional Pytest command-line options for tests:
93+
SeleniumBase provides additional ``pytest`` command-line options for tests:
94+
9095
```bash
91-
--browser=BROWSER # (The web browser to use.)
96+
--browser=BROWSER # (The web browser to use. Default: "chrome")
9297
--cap-file=FILE # (The web browser's desired capabilities to use.)
9398
--cap-string=STRING # (The web browser's desired capabilities to use.)
94-
--settings-file=FILE # (Overrides SeleniumBase settings.py values.)
99+
--settings-file=FILE # (Override default SeleniumBase settings.)
95100
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
96-
--data=DATA # (Extra data to pass to tests. Use "self.data" in tests.)
97-
--var1=DATA # (Extra data to pass to tests. Use "self.var1" in tests.)
98-
--var2=DATA # (Extra data to pass to tests. Use "self.var2" in tests.)
99-
--var3=DATA # (Extra data to pass to tests. Use "self.var3" in tests.)
101+
--data=DATA # (Extra test data. Access with "self.data" in tests.)
102+
--var1=DATA # (Extra test data. Access with "self.var1" in tests.)
103+
--var2=DATA # (Extra test data. Access with "self.var2" in tests.)
104+
--var3=DATA # (Extra test data. Access with "self.var3" in tests.)
100105
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
101106
--server=SERVER # (The server / IP address used by the tests.)
102107
--port=PORT # (The port that's used by the test server.)
103108
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
104-
--agent=STRING # (This designates the web browser's User Agent to use.)
105-
--mobile # (The option to use the mobile emulator while running tests.)
106-
--metrics=STRING # ("CSSWidth,Height,PixelRatio" for mobile emulator tests.)
109+
--agent=STRING # (Modify the web browser's User-Agent string.)
110+
--mobile # (Use the mobile device emulator while running tests.)
111+
--metrics=STRING # (Set mobile "CSSWidth,CSSHeight,PixelRatio".)
107112
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
108113
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
109-
--headless # (The option to run tests headlessly. The default on Linux OS.)
110-
--headed # (The option to run tests with a GUI on Linux OS.)
114+
--headless # (Run tests headlessly. Default mode on Linux OS.)
115+
--headed # (Run tests with a GUI on Linux OS.)
111116
--start-page=URL # (The starting URL for the web browser when tests begin.)
112117
--archive-logs # (Archive old log files instead of deleting them.)
113118
--time-limit=SECONDS # (Safely fail any test that exceeds the limit limit.)
114-
--slow # (The option to slow down the automation.)
115-
--demo # (The option to visually see test actions as they occur.)
116-
--demo-sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
119+
--slow # (Slow down the automation. Faster than using Demo Mode.)
120+
--demo # (Slow down and visually see test actions as they occur.)
121+
--demo-sleep=SECONDS # (Set the wait time after Demo Mode actions.)
117122
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
118123
--message-duration=SECONDS # (The time length for Messenger alerts.)
119-
--check-js # (The option to check for JavaScript errors after page loads.)
120-
--ad-block # (The option to block some display ads after page loads.)
121-
--block-images # (The option to block images from loading during tests.)
124+
--check-js # (Check for JavaScript errors after page loads.)
125+
--ad-block # (Block some types of display ads after page loads.)
126+
--block-images # (Block images from loading during tests.)
122127
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
123128
--disable-csp # (This disables the Content Security Policy of websites.)
124-
--enable-sync # (The option to enable "Chrome Sync".)
125-
--use-auto-ext # (The option to use Chrome's automation extension.)
126-
--swiftshader # (The option to use Chrome's "--use-gl=swiftshader" feature.)
127-
--incognito # (The option to enable Chrome's Incognito mode.)
128-
--guest # (The option to enable Chrome's Guest mode.)
129-
--devtools # (The option to open Chrome's DevTools when the browser opens.)
130-
--reuse-session # (The option to reuse the browser session between tests.)
131-
--crumbs # (Option to delete all cookies between tests reusing a session.)
132-
--maximize-window # (The option to start with the web browser maximized.)
133-
--save-screenshot # (The option to save a screenshot after each test.)
129+
--enable-sync # (Enable "Chrome Sync".)
130+
--use-auto-ext # (Use Chrome's automation extension.)
131+
--swiftshader # (Use Chrome's "--use-gl=swiftshader" feature.)
132+
--incognito # (Enable Chrome's Incognito mode.)
133+
--guest # (Enable Chrome's Guest mode.)
134+
--devtools # (Open Chrome's DevTools when the browser opens.)
135+
--reuse-session # (Reuse the browser session between tests.)
136+
--crumbs # (Delete all cookies between tests reusing a session.)
137+
--maximize-window # (Start tests with the web browser window maximized.)
138+
--save-screenshot # (Save a screenshot at the end of each test.)
134139
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
135140
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
136141
```
142+
137143
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
138144

145+
You can also view a list of popular ``pytest`` options for SeleniumBase by typing:
146+
147+
```bash
148+
seleniumbase options
149+
```
150+
151+
Or the short form:
152+
153+
```bash
154+
sbase options
155+
```
156+
139157
### <img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Customizing default settings:
140158

141159
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.
@@ -181,6 +199,7 @@ Or you can create your own Selenium Grid for test distribution. ([See this ReadM
181199
```bash
182200
pytest test_suite.py --browser=chrome
183201
```
202+
184203
(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.)
185204

186205
### <img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Demo Mode:
@@ -214,14 +233,15 @@ pytest --reruns=2 --reruns-delay=1
214233

215234
### <img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Debugging tests:
216235

217-
**You can use the following code snippets in your scripts to help you debug issues:**
236+
You can use the following calls in your scripts to help you debug issues:
237+
218238
```python
219239
import time; time.sleep(5) # Makes the test wait and do nothing for 5 seconds.
220240
import ipdb; ipdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
221241
import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
222242
```
223243

224-
**To pause an active test that throws an exception or error, add ``--pdb -s``:**
244+
To pause an active test that throws an exception or error, add ``--pdb -s``:
225245

226246
```bash
227247
pytest my_first_test.py --pdb -s

seleniumbase/plugins/base_plugin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
class Base(Plugin):
1414
"""
1515
This parser plugin includes the following command-line options for Nose:
16-
--env=ENV (Set a test environment. Use "self.env" to use this in tests.)
17-
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
18-
--var1=DATA (Extra data to pass to tests. Use "self.var1" in tests.)
19-
--var2=DATA (Extra data to pass to tests. Use "self.var2" in tests.)
20-
--var3=DATA (Extra data to pass to tests. Use "self.var3" in tests.)
21-
--settings-file=FILE (Overrides SeleniumBase settings.py values.)
16+
--env=ENV (Set the test env. Access with "self.env" in tests.)
17+
--data=DATA (Extra test data. Access with "self.data" in tests.)
18+
--var1=DATA (Extra test data. Access with "self.var1" in tests.)
19+
--var2=DATA (Extra test data. Access with "self.var2" in tests.)
20+
--var3=DATA (Extra test data. Access with "self.var3" in tests.)
21+
--settings-file=FILE (Override default SeleniumBase settings.)
2222
--archive-logs (Archive old log files instead of deleting them.)
23-
--report (The option to create a fancy report after tests complete.)
23+
--report (Create a fancy nosetests report after tests complete.)
2424
--show-report If self.report is turned on, then the report will
2525
display immediately after tests complete their run.
2626
Only use this when running tests locally, as this will

seleniumbase/plugins/pytest_plugin.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,50 @@
1111

1212
def pytest_addoption(parser):
1313
"""
14-
This parser plugin includes the following command-line options for pytest:
15-
--browser=BROWSER (The web browser to use.)
14+
This plugin adds the following command-line options to pytest:
15+
--browser=BROWSER (The web browser to use. Default: "chrome")
1616
--cap-file=FILE (The web browser's desired capabilities to use.)
1717
--cap-string=STRING (The web browser's desired capabilities to use.)
18-
--settings-file=FILE (Overrides SeleniumBase settings.py values.)
19-
--env=ENV (Set a test environment. Use "self.env" to use this in tests.)
20-
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
21-
--var1=DATA (Extra data to pass to tests. Use "self.var1" in tests.)
22-
--var2=DATA (Extra data to pass to tests. Use "self.var2" in tests.)
23-
--var3=DATA (Extra data to pass to tests. Use "self.var3" in tests.)
18+
--settings-file=FILE (Override default SeleniumBase settings.)
19+
--env=ENV (Set the test env. Access with "self.env" in tests.)
20+
--data=DATA (Extra test data. Access with "self.data" in tests.)
21+
--var1=DATA (Extra test data. Access with "self.var1" in tests.)
22+
--var2=DATA (Extra test data. Access with "self.var2" in tests.)
23+
--var3=DATA (Extra test data. Access with "self.var3" in tests.)
2424
--user-data-dir=DIR (Set the Chrome user data directory to use.)
2525
--server=SERVER (The server / IP address used by the tests.)
2626
--port=PORT (The port that's used by the test server.)
2727
--proxy=SERVER:PORT (This is the proxy server:port combo used by tests.)
28-
--agent=STRING (This designates the web browser's User Agent to use.)
29-
--mobile (The option to use the mobile emulator while running tests.)
30-
--metrics=STRING ("CSSWidth,Height,PixelRatio" for mobile emulator tests.)
28+
--agent=STRING (Modify the web browser's User-Agent string.)
29+
--mobile (Use the mobile device emulator while running tests.)
30+
--metrics=STRING (Set mobile "CSSWidth,CSSHeight,PixelRatio".)
3131
--extension-zip=ZIP (Load a Chrome Extension .zip file, comma-separated.)
3232
--extension-dir=DIR (Load a Chrome Extension directory, comma-separated.)
33-
--headless (The option to run tests headlessly. The default on Linux OS.)
34-
--headed (The option to run tests with a GUI on Linux OS.)
33+
--headless (Run tests headlessly. Default mode on Linux OS.)
34+
--headed (Run tests with a GUI on Linux OS.)
3535
--start-page=URL (The starting URL for the web browser when tests begin.)
3636
--archive-logs (Archive old log files instead of deleting them.)
3737
--time-limit=SECONDS (Safely fail any test that exceeds the limit limit.)
38-
--slow (The option to slow down the automation.)
39-
--demo (The option to visually see test actions as they occur.)
40-
--demo-sleep=SECONDS (The option to wait longer after Demo Mode actions.)
38+
--slow (Slow down the automation. Faster than using Demo Mode.)
39+
--demo (Slow down and visually see test actions as they occur.)
40+
--demo-sleep=SECONDS (Set the wait time after Demo Mode actions.)
4141
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
4242
--message-duration=SECONDS (The time length for Messenger alerts.)
43-
--check-js (The option to check for JavaScript errors after page loads.)
44-
--ad-block (The option to block some display ads after page loads.)
45-
--block-images (The option to block images from loading during tests.)
43+
--check-js (Check for JavaScript errors after page loads.)
44+
--ad-block (Block some types of display ads after page loads.)
45+
--block-images (Block images from loading during tests.)
4646
--verify-delay=SECONDS (The delay before MasterQA verification checks.)
47-
--disable-csp (This disables the Content Security Policy of websites.)
48-
--enable-sync (The option to enable "Chrome Sync".)
49-
--use-auto-ext (The option to use Chrome's automation extension.)
50-
--swiftshader (The option to use Chrome's "--use-gl=swiftshader" feature.)
51-
--incognito (The option to enable Chrome's Incognito mode.)
52-
--guest (The option to enable Chrome's Guest mode.)
53-
--devtools (The option to open Chrome's DevTools when the browser opens.)
54-
--reuse-session (The option to reuse the browser session between tests.)
55-
--crumbs (Option to delete all cookies between tests reusing a session.)
56-
--maximize (The option to start with the web browser maximized.)
57-
--save-screenshot (The option to save a screenshot after each test.)
47+
--disable-csp (Disable the Content Security Policy of websites.)
48+
--enable-sync (Enable "Chrome Sync".)
49+
--use-auto-ext (Use Chrome's automation extension.)
50+
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
51+
--incognito (Enable Chrome's Incognito mode.)
52+
--guest (Enable Chrome's Guest mode.)
53+
--devtools (Open Chrome's DevTools when the browser opens.)
54+
--reuse-session / --rs (Reuse the browser session between tests.)
55+
--crumbs (Delete all cookies between tests reusing a session.)
56+
--maximize (Start tests with the web browser window maximized.)
57+
--save-screenshot (Save a screenshot at the end of each test.)
5858
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
5959
--timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
6060
"""

0 commit comments

Comments
 (0)