Skip to content

Commit 78296e6

Browse files
committed
Update the ReadMe
1 parent 6bae5d9 commit 78296e6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ SeleniumBase automatically handles common WebDriver actions such as spinning up
2121

2222
(<i>By default, [CSS Selectors](https://www.w3schools.com/cssref/css_selectors.asp) are used for finding page elements.</i>)
2323

24-
**Run tests with Pytest or Nose in any browser:**
24+
**Run tests with Pytest or Nose in any browser:**<br />
25+
(<i>Using **Pytest** is strongly recommended</i>)
2526

2627
```bash
2728
pytest my_first_test.py --browser=chrome
@@ -137,7 +138,7 @@ class MyTestClass(BaseCase):
137138

138139
**Here's how to run the example script on various web browsers:**
139140

140-
(NOTE: You can interchange **nosetests** with **pytest** at anytime.)
141+
(NOTE: You can interchange **pytest** with **nosetests** at anytime.)
141142

142143
```bash
143144
cd examples/
@@ -158,7 +159,7 @@ pytest my_first_test.py --browser=chrome --demo_mode
158159
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.)
159160

160161
```bash
161-
nosetests my_first_test.py --browser=chrome --demo_mode --demo_sleep=1.2
162+
pytest my_first_test.py --browser=chrome --demo_mode --demo_sleep=1.2
162163
```
163164

164165
You can also use the following in your scripts to slow down the tests:
@@ -168,14 +169,14 @@ import time; time.sleep(5) # sleep for 5 seconds (add this after the line you w
168169
import ipdb; ipdb.set_trace() # waits for your command. n = next line of current method, c = continue, s = step / next executed line (will jump)
169170
```
170171

171-
(NOTE: If you're using pytest instead of nosetests and you want to use ipdb in your script for debugging purposes, you'll either need to add ``--capture=no`` on the command line, or use ``import pytest; pytest.set_trace()`` instead of using ipdb. More info on that [here](http://stackoverflow.com/questions/2678792/can-i-debug-with-python-debugger-when-using-py-test-somehow).)
172+
(NOTE: If you're using pytest instead of nosetests and you want to use ipdb in your script for debugging purposes, you'll need to add ``--capture=no`` (or ``-s``) on the command line, or use ``import pytest; pytest.set_trace()`` instead of using ipdb. More info on that [here](http://stackoverflow.com/questions/2678792/can-i-debug-with-python-debugger-when-using-py-test-somehow).)
172173

173174
You may also want to have your test sleep in other situations where you need to have your test wait for something. If you know what you're waiting for, you should be specific by using a command that waits for something specific to happen.
174175

175176
If you need to debug things on the fly (in case of errors), use this:
176177

177178
```bash
178-
nosetests my_first_test.py --browser=chrome --pdb --pdb-failures -s
179+
pytest my_first_test.py --browser=chrome --pdb --pdb-failures -s
179180
```
180181

181182
The above code (with --pdb) will leave your browser window open in case there's a failure, which is possible if the web pages from the example change the data that's displayed on the page. (ipdb commands: 'c', 's', 'n' => continue, step, next). You may need the ``-s`` in order to see all console output.
@@ -207,7 +208,7 @@ For running tests outside of the SeleniumBase repo with **Nosetests**, you'll wa
207208

208209
If you want to pass additional data from the command line to your tests, you can use ``--data=STRING``. Now inside your tests, you can use ``self.data`` to access that.
209210

210-
To run Pytest multithreaded on multiple CPUs at the same time, add ``-n NUM`` on the command line, where NUM is the number of CPUs you want to use.
211+
To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or ``-n NUM`` on the command line, where NUM is the number of CPUs you want to use.
211212

212213
<img src="https://cdn2.hubspot.net/hubfs/100006/images/logo_base_4b.png" title="SeleniumBase" height="120">
213214

@@ -282,7 +283,7 @@ pip install mysqlclient==1.3.12
282283

283284
Here's an example of running tests with additional features enabled:
284285
```bash
285-
nosetests [YOUR_TEST_FILE].py --browser=chrome --with-db_reporting --with-s3_logging -s
286+
pytest [YOUR_TEST_FILE].py --browser=chrome --with-db_reporting --with-s3_logging -s
286287
```
287288
(NOTE: If you haven't configured your MySQL or S3 connections in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), don't use ``--with-db_reporting`` or ``--with-s3_logging``.)
288289

@@ -296,10 +297,11 @@ nosetests [YOUR_TEST_FILE].py --config=[MY_CONFIG_FILE].cfg
296297

297298
You can simplify that even more by using a setup.cfg file, such as the one provided for you in the examples folder. If you kick off a test run from within the folder that setup.cfg is location in, that file will automatically be used as your configuration, meaning that you wouldn't have to type out all the plugins that you want to use (or include a config file) everytime you run tests.
298299

299-
If you tell nosetests to run an entire file, it will run every method in that python file that starts with "test". You can be more specific on what to run by doing something like:
300+
If you tell pytest/nosetests to run an entire file, it will run every method in that python file that starts with "test". You can be more specific on what to run by doing something like the following: (<i>Note that the syntax is different for pytest vs nosetests.</i>)
300301

301302
```bash
302-
nosetests [YOUR_TEST_FILE].py:[SOME_CLASS_NAME].test_[SOME_TEST_NAME] --config=[MY_CONFIG_FILE].cfg
303+
pytest [YOUR_TEST_FILE].py::[SOME_CLASS_NAME]::test_[SOME_TEST_NAME]
304+
nosetests [YOUR_TEST_FILE].py:[SOME_CLASS_NAME].test_[SOME_TEST_NAME]
303305
```
304306

305307
Let's try an example of a test that fails:
@@ -317,7 +319,7 @@ class MyTestClass(BaseCase):
317319
You can run it from the ``examples`` folder like this:
318320

319321
```bash
320-
nosetests test_fail.py
322+
pytest test_fail.py
321323
```
322324

323325
You'll notice that a logs folder, "latest_logs", was created to hold information about the failing test, and screenshots. Take a look at what you get. Remember, this data can be saved in your MySQL DB and in S3 if you include the necessary plugins in your run command (and if you set up the neccessary connections properly). For future test runs, past test results will get stored in the archived_logs folder if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py).

0 commit comments

Comments
 (0)