Skip to content

Commit abf269f

Browse files
authored
Merge pull request #438 from seleniumbase/refactor-docs-and-cmd-args
Refactor docs and command-line arguments
2 parents 8e47dad + 0673de7 commit abf269f

File tree

6 files changed

+132
-114
lines changed

6 files changed

+132
-114
lines changed

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ self.execute_script(JAVASCRIPT) # Execute javascript code
8585
self.go_back() # Navigate to the previous URL
8686
self.get_text(SELECTOR) # Get text from a selector
8787
self.get_attribute(SELECTOR, ATTRIBUTE) # Get a specific attribute from a selector
88-
self.is_element_visible(SELECTOR) # Find out if an element is visible on the page
89-
self.is_text_visible(TEXT) # Find out if specific text is visible on the page (optional SELECTOR arg)
90-
self.hover_and_click(HOVER_SELECTOR, CLICK_SELECTOR) # Mouseover an element and click another element
88+
self.is_element_visible(SELECTOR) # Determine if an element is visible on the page
89+
self.is_text_visible(TEXT) # Determine if text is visible on the page (optional SELECTOR)
90+
self.hover_and_click(HOVER_SELECTOR, CLICK_SELECTOR) # Mouseover element & click another
9191
self.select_option_by_text(DROPDOWN_SELECTOR, OPTION_TEXT) # Select a dropdown option
9292
self.switch_to_frame(FRAME_NAME) # Switch webdriver control to an iframe on the page
9393
self.switch_to_default_content() # Switch webdriver control out of the current iframe
@@ -178,9 +178,9 @@ pytest --collect-only -q
178178
You can use the following in your scripts to help you debug issues:
179179
(<i>If using ipdb, make sure you add "-s" to command-line options unless already in pytest.ini</i>)
180180
```python
181-
import time; time.sleep(5) # Sleeps for 5 seconds (add this after the line you want to pause on)
182-
import ipdb; ipdb.set_trace() # Waits for user input. n = next line, c = continue, s = step.
183-
import pytest; pytest.set_trace() # Waits for user input. n = next line, c = continue, s = step.
181+
import time; time.sleep(5) # Makes the test wait and do nothing for 5 seconds.
182+
import ipdb; ipdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
183+
import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
184184
```
185185

186186
**To pause an active test that throws an exception or error, add ``--pdb -s``:**
@@ -194,7 +194,7 @@ Here are some other useful command-line options that come with Pytest:
194194
-v # Prints the full test name for each test.
195195
-q # Prints fewer details in the console output when running tests.
196196
-x # Stop running the tests after the first failure is reached.
197-
--html=report.html # Creates a detailed test report after tests complete. (Using the pytest-html plugin)
197+
--html=report.html # Creates a detailed pytest-html report after tests finish.
198198
--collect-only # Show what tests would get run without actually running them.
199199
-s # See print statements. (Should be on by default with pytest.ini present.)
200200
-n=NUM # Multithread the tests using that many threads. (Speed up test runs!)
@@ -203,36 +203,37 @@ Here are some other useful command-line options that come with Pytest:
203203
SeleniumBase provides additional Pytest command-line options for tests:
204204
```bash
205205
--browser=BROWSER # (The web browser to use.)
206-
--cap_file=FILE # (The web browser's desired capabilities to use.)
207-
--settings_file=FILE # (Overrides SeleniumBase settings.py values.)
206+
--cap-file=FILE # (The web browser's desired capabilities to use.)
207+
--settings-file=FILE # (Overrides SeleniumBase settings.py values.)
208208
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
209209
--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.)
211211
--server=SERVER # (The server / IP address used by the tests.)
212212
--port=PORT # (The port that's used by the test server.)
213213
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
214214
--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.)
217217
--headless # (The option to run tests headlessly. The default on Linux OS.)
218218
--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.)
222222
--slow # (The option to slow down the automation.)
223223
--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.)
225225
--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.)
236237
```
237238
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
238239

examples/ReadMe.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pytest my_first_test.py --browser=firefox
2222

2323
Run an example test in Demo Mode (highlights page objects being acted on):
2424
```bash
25-
pytest my_first_test.py --demo_mode
25+
pytest my_first_test.py --demo
2626
```
2727

2828
Run an example test demonstrating parameterization:
@@ -37,7 +37,7 @@ pytest test_suite.py --html=report.html
3737

3838
Run an example test suite and generate a nosetest report: (nosetests-only)
3939
```bash
40-
nosetests test_suite.py --report --show_report
40+
nosetests test_suite.py --report --show-report
4141
```
4242

4343
Run an example test using a nosetest configuration file: (nosetests-only)
@@ -60,6 +60,11 @@ Run a failing test with Debugging-mode enabled: (If a test failure occurs, pdb a
6060
pytest test_fail.py --pdb -s
6161
```
6262

63+
Run an example test suite that reuses the browser session between tests:
64+
```bash
65+
pytest test_suite.py --reuse-session
66+
```
67+
6368
Run an example test suite that demonstrates the use of pytest markers:
6469
```bash
6570
pytest -v -m marker_test_suite

help_docs/customizing_test_runs.md

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ In addition to [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/m
1111
* Choose the User-Agent for the browser to use
1212
* Choose the automation speed (with Demo Mode)
1313
* Choose whether to run tests multi-threaded
14-
* Choose whether to retry failing tests
15-
* Choose a Chrome User Data Directory to use
14+
* Choose whether to rerun failing tests
15+
* Choose whether to reuse the browser session
1616
* Choose a Chrome Extension to load
17+
* Choose a Chrome User Data Directory to use
1718
* Choose a BrowserStack server to run on
1819
* Choose a Sauce Labs server to run on
1920
* Choose a TestingBot server to run on
@@ -26,34 +27,37 @@ In addition to [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/m
2627

2728
#### **Examples:**
2829

29-
(These are run from the **[examples](https://github.com/seleniumbase/SeleniumBase/tree/master/examples)** folder.)
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.)
3032

3133
```bash
3234
pytest my_first_test.py
3335

34-
pytest my_first_test.py --demo_mode --browser=chrome
36+
pytest my_first_test.py --demo
3537

3638
pytest my_first_test.py --browser=firefox
3739

3840
pytest test_suite.py --html=report.html
3941

40-
nosetests test_suite.py --report --show_report
42+
nosetests test_suite.py --report --show-report
4143

42-
pytest test_suite.py --headless -n 4
44+
pytest test_suite.py --headless -n=4
4345

44-
pytest test_suite.py --reruns 1 --reruns-delay 2
46+
pytest test_suite.py --reruns=1 --reruns-delay=1
4547

4648
pytest test_suite.py --server=IP_ADDRESS --port=4444
4749

50+
pytest test_suite.py --reuse-session
51+
4852
pytest test_fail.py --pdb -s
4953

5054
pytest proxy_test.py --proxy=IP_ADDRESS:PORT
5155

5256
pytest proxy_test.py --proxy=USERNAME:PASSWORD@IP_ADDRESS:PORT
5357

54-
pytest user_agent_test.py --agent="USER-AGENT STRING"
58+
pytest user_agent_test.py --agent="USER-AGENT-STRING"
5559

56-
pytest my_first_test.py --settings_file=custom_settings.py
60+
pytest my_first_test.py --settings-file=custom_settings.py
5761
```
5862

5963
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
6266

6367
An easy way to override seleniumbase/config/settings.py is by using a custom settings file.
6468
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``
6670
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, and other important settings used by tests.)
6771

6872
#### **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):**
@@ -103,16 +107,16 @@ pytest test_suite.py --browser=chrome
103107

104108
#### **Demo Mode:**
105109

106-
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:
107111

108112
```bash
109-
pytest my_first_test.py --browser=chrome --demo_mode
113+
pytest my_first_test.py --demo
110114
```
111115

112-
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.)
113117

114118
```bash
115-
pytest my_first_test.py --browser=chrome --demo_mode --demo_sleep=1.2
119+
pytest my_first_test.py --demo --demo-sleep=1.2
116120
```
117121

118122
#### **Passing additional data to tests:**
@@ -125,24 +129,24 @@ To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or
125129

126130
#### **Retrying failing tests automatically:**
127131

128-
You can use ``--reruns NUM`` to retry failing tests that many times. Use ``--reruns-delay SECONDS`` 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:
129133
```
130-
pytest --reruns 5 --reruns-delay 1
134+
pytest --reruns=2 --reruns-delay=1
131135
```
132136

133137
#### **Debugging tests:**
134138

135139
**You can use the following code snippets in your scripts to help you debug issues:**
136140
```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.
140144
```
141145

142146
**To pause an active test that throws an exception or error, add ``--pdb -s``:**
143147

144148
```bash
145-
pytest my_first_test.py --browser=chrome --pdb -s
149+
pytest my_first_test.py --pdb -s
146150
```
147151

148152
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:
181185
SeleniumBase provides additional Pytest command-line options for tests:
182186
```bash
183187
--browser=BROWSER # (The web browser to use.)
184-
--cap_file=FILE # (The web browser's desired capabilities to use.)
185-
--settings_file=FILE # (Overrides SeleniumBase settings.py values.)
188+
--cap-file=FILE # (The web browser's desired capabilities to use.)
189+
--settings-file=FILE # (Overrides SeleniumBase settings.py values.)
186190
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
187191
--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.)
189193
--server=SERVER # (The server / IP address used by the tests.)
190194
--port=PORT # (The port that's used by the test server.)
191195
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
192196
--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.)
195199
--headless # (The option to run tests headlessly. The default on Linux OS.)
196200
--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.)
200204
--slow # (The option to slow down the automation.)
201205
--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.)
203207
--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.)
214219
```
215220
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
216221

@@ -236,7 +241,7 @@ pytest proxy_test.py --proxy=proxy1
236241

237242
#### **Changing the User-Agent:**
238243

239-
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.
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.
240245

241246
```bash
242247
pytest user_agent_test.py --agent="Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7412.EU"

0 commit comments

Comments
 (0)