Skip to content

Commit fc2c876

Browse files
authored
Merge pull request #254 from seleniumbase/update-examples
Update example tests
2 parents 442feed + b887564 commit fc2c876

File tree

13 files changed

+80
-36
lines changed

13 files changed

+80
-36
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ SeleniumBase automatically handles common WebDriver actions such as spinning up
8888
```
8989
pytest my_first_test.py --browser=chrome
9090
91-
nosetests my_test_suite.py --browser=firefox
91+
nosetests test_suite.py --browser=firefox
9292
```
9393

9494
Python methods that start with ``test_`` will automatically be run when using ``pytest`` or ``nosetests`` on a Python file, (<i>or on folders containing Python files</i>).
@@ -248,14 +248,14 @@ Here are some other useful **nosetest**-specific arguments:
248248
--with-id # If -v is also used, will number the tests for easy counting.
249249
```
250250

251-
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. The ``my_test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
251+
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. The ``test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
252252

253253
```
254254
cd examples/
255255
256-
pytest my_test_suite.py --browser=chrome
256+
pytest test_suite.py --browser=chrome
257257
258-
pytest my_test_suite.py --browser=firefox
258+
pytest test_suite.py --browser=firefox
259259
```
260260

261261
If you want to run tests headlessly, use ``--headless``, which you'll need to do if your system lacks a GUI interface. Even if your system does have a GUI interface, it may still support headless browser automation.
@@ -311,23 +311,23 @@ pytest my_first_test.py --browser=chrome
311311
Using ``--html=report.html`` gives you a fancy report of the name specified after your test suite completes.
312312

313313
```
314-
pytest my_test_suite.py --html=report.html
314+
pytest test_suite.py --html=report.html
315315
```
316316

317317
![](https://cdn2.hubspot.net/hubfs/100006/images/PytestReport.png "Example Pytest Report")
318318

319319
You can also use ``--junitxml=report.xml`` to get an xml report instead. Jenkins can use this file to display better reporting for your tests.
320320

321321
```
322-
pytest my_test_suite.py --junitxml=report.xml
322+
pytest test_suite.py --junitxml=report.xml
323323
```
324324

325325
#### **Nosetest Reports:**
326326

327327
The ``--report`` option gives you a fancy report after your test suite completes.
328328

329329
```
330-
nosetests my_test_suite.py --report
330+
nosetests test_suite.py --report
331331
```
332332
<img src="https://cdn2.hubspot.net/hubfs/100006/images/Test_Report_2.png" title="Example Nosetest Report" height="420">
333333

examples/ReadMe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ pytest my_first_test.py --browser=chrome --demo_mode
2727

2828
Run the example test suite and generate an pytest report: (pytest-only)
2929
```bash
30-
pytest basic_script.py --html=report.html
30+
pytest test_suite.py --html=report.html
3131
```
3232

3333
Run the example test suite and generate a nosetest report: (nosetests-only)
3434
```bash
35-
nosetests my_test_suite.py --report --show_report
35+
nosetests test_suite.py --report --show_report
3636
```
3737

3838
Run a test using a nosetest configuration file: (nosetests-only)
File renamed without changes.

examples/delayed_assert_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import pytest
12
from seleniumbase import BaseCase
23

34

45
class MyTestClass(BaseCase):
56

7+
@pytest.mark.expected_failure
68
def test_delayed_asserts(self):
79
self.open('https://xkcd.com/993/')
810
self.wait_for_element('#comic')

examples/example_logs/ReadMe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Reports are most useful when running large test suites. Pytest and Nosetest repo
2323
Using ``--html=report.html`` gives you a fancy report of the name specified after your test suite completes.
2424

2525
```bash
26-
pytest my_test_suite.py --html=report.html
26+
pytest test_suite.py --html=report.html
2727
```
2828
![](https://cdn2.hubspot.net/hubfs/100006/images/PytestReport.png "Example Pytest Report")
2929

@@ -32,7 +32,7 @@ pytest my_test_suite.py --html=report.html
3232
The ``--report`` option gives you a fancy report after your test suite completes. (Requires ``--with-testing_base`` to also be set when ``--report`` is used because it's part of that plugin.)
3333

3434
```bash
35-
nosetests my_test_suite.py --report --browser=chrome
35+
nosetests test_suite.py --report --browser=chrome
3636
```
3737
<img src="https://cdn2.hubspot.net/hubfs/100006/images/Test_Report_2.png" title="Example Nosetest Report" height="420">
3838

examples/gui_test_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, master):
5252
fg="blue").pack()
5353
self.run5 = Button(
5454
frame, command=self.run_5,
55-
text=("nosetests my_test_suite.py --report --show_report")).pack()
55+
text=("nosetests test_suite.py --report --show_report")).pack()
5656
self.title6 = Label(
5757
frame,
5858
text="Basic Failing Test Run showing the Multiple-Checks feature:",
@@ -66,7 +66,7 @@ def __init__(self, master):
6666
fg="blue").pack()
6767
self.run7 = Button(
6868
frame, command=self.run_7,
69-
text=("nosetests my_test_suite.py"
69+
text=("nosetests test_suite.py"
7070
" --browser=chrome --with-db_reporting")).pack()
7171
self.end_title = Label(frame, text="", fg="black").pack()
7272
self.quit = Button(frame, text="QUIT", command=frame.quit).pack()
@@ -90,15 +90,15 @@ def run_4(self):
9090

9191
def run_5(self):
9292
os.system(
93-
'nosetests my_test_suite.py --report --show_report')
93+
'nosetests test_suite.py --report --show_report')
9494

9595
def run_6(self):
9696
os.system(
9797
'nosetests delayed_assert_test.py --browser=chrome')
9898

9999
def run_7(self):
100100
os.system(
101-
'nosetests my_test_suite.py'
101+
'nosetests test_suite.py'
102102
' --browser=chrome --with-db_reporting')
103103

104104

examples/test_fail.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
""" This test was made to fail on purpose to demonstrate the
22
logging capabilities of the SeleniumBase Test Framework """
33

4+
import pytest
45
from seleniumbase import BaseCase
56

67

78
class MyTestClass(BaseCase):
89

10+
@pytest.mark.expected_failure
911
def test_find_army_of_robots_on_xkcd_desert_island(self):
1012
self.open("https://xkcd.com/731/")
1113
print("\n(This test fails on purpose)")

examples/test_markers.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
""" These tests demonstrate pytest marker use for finding and running tests.
2+
3+
Usage examples from this file:
4+
pytest -v -m marker_test_suite # Runs A, B, C, D
5+
pytest -v -m marker1 # Runs A
6+
pytest -v -m marker2 # Runs B, C
7+
pytest -v -m xkcd_code # Runs C
8+
pytest test_markers.py -v -m "not marker2" # Runs A, D
9+
10+
(The "-v" will display the names of tests as they run.)
11+
(Add "--collect-only" to display names of tests without running them.)
12+
"""
13+
14+
import pytest
15+
from seleniumbase import BaseCase
16+
17+
18+
@pytest.mark.marker_test_suite
19+
class MarkerTestSuite(BaseCase):
20+
21+
@pytest.mark.marker1
22+
def test_A(self):
23+
self.open("https://xkcd.com/1319/")
24+
self.assert_text("Automation", "div#ctitle")
25+
26+
@pytest.mark.marker2
27+
def test_B(self):
28+
self.open("https://www.xkcd.com/1700/")
29+
self.assert_text("New Bug", "div#ctitle")
30+
31+
@pytest.mark.marker2
32+
@pytest.mark.xkcd_code # Tests can have multiple markers
33+
def test_C(self):
34+
self.open("https://xkcd.com/844/")
35+
self.assert_text("Good Code", "div#ctitle")
36+
37+
def test_D(self):
38+
self.open("https://xkcd.com/2021/")
39+
self.assert_text("Software Development", "div#ctitle")
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
''' NOTE: This test suite contains 2 passing tests and 2 failing tests. '''
22

3+
import pytest
34
from seleniumbase import BaseCase
45

56

67
class MyTestSuite(BaseCase):
78

89
def test_1(self):
910
self.open("https://xkcd.com/1663/")
10-
self.find_text("Garden", "div#ctitle", timeout=3)
11+
self.assert_text("Garden", "div#ctitle", timeout=3)
1112
for p in range(4):
1213
self.click('a[rel="next"]')
13-
self.find_text("Algorithms", "div#ctitle", timeout=3)
14+
self.assert_text("Algorithms", "div#ctitle", timeout=3)
1415

16+
@pytest.mark.expected_failure
1517
def test_2(self):
16-
# This test should FAIL
1718
print("\n(This test fails on purpose)")
1819
self.open("https://xkcd.com/1675/")
1920
raise Exception("FAKE EXCEPTION: This test fails on purpose.")
2021

2122
def test_3(self):
2223
self.open("https://xkcd.com/1406/")
23-
self.find_text("Universal Converter Box", "div#ctitle", timeout=3)
24+
self.assert_text("Universal Converter Box", "div#ctitle", timeout=3)
2425
self.open("https://xkcd.com/608/")
25-
self.find_text("Form", "div#ctitle", timeout=3)
26+
self.assert_text("Form", "div#ctitle", timeout=3)
2627

28+
@pytest.mark.expected_failure
2729
def test_4(self):
28-
# This test should FAIL
2930
print("\n(This test fails on purpose)")
3031
self.open("https://xkcd.com/1670/")
31-
self.find_element("FakeElement.DoesNotExist", timeout=0.5)
32+
self.assert_element("FakeElement.DoesNotExist", timeout=0.5)

help_docs/customizing_test_runs.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ pytest my_first_test.py --demo_mode --browser=chrome
2828

2929
pytest my_first_test.py --browser=firefox
3030

31-
pytest my_test_suite.py --html=report.html
31+
pytest test_suite.py --html=report.html
3232

33-
nosetests my_test_suite.py --report --show_report
33+
nosetests test_suite.py --report --show_report
3434

35-
pytest my_test_suite.py --headless -n 4
35+
pytest test_suite.py --headless -n 4
3636

37-
pytest my_test_suite.py --server=IP_ADDRESS --port=4444
37+
pytest test_suite.py --server=IP_ADDRESS --port=4444
3838

39-
pytest my_test_suite.py --proxy=IP_ADDRESS:PORT
39+
pytest test_suite.py --proxy=IP_ADDRESS:PORT
4040

41-
pytest my_test_suite.py --proxy=USERNAME:PASSWORD@IP_ADDRESS:PORT
41+
pytest test_suite.py --proxy=USERNAME:PASSWORD@IP_ADDRESS:PORT
4242

4343
pytest test_fail.py --pdb -s
4444
```
@@ -72,7 +72,7 @@ Or you can create your own Selenium Grid for test distribution. ([See this ReadM
7272
#### **Example tests using Logging:**
7373

7474
```bash
75-
pytest my_test_suite.py --browser=chrome
75+
pytest test_suite.py --browser=chrome
7676
```
7777
(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.)
7878

@@ -120,7 +120,7 @@ The code above will leave your browser window open in case there's a failure. (i
120120
Using ``--html=report.html`` gives you a fancy report of the name specified after your test suite completes.
121121

122122
```bash
123-
pytest my_test_suite.py --html=report.html
123+
pytest test_suite.py --html=report.html
124124
```
125125
![](https://cdn2.hubspot.net/hubfs/100006/images/PytestReport.png "Example Pytest Report")
126126

@@ -129,7 +129,7 @@ pytest my_test_suite.py --html=report.html
129129
The ``--report`` option gives you a fancy report after your test suite completes.
130130

131131
```bash
132-
nosetests my_test_suite.py --report
132+
nosetests test_suite.py --report
133133
```
134134
<img src="https://cdn2.hubspot.net/hubfs/100006/images/Test_Report_2.png" title="Example Nosetest Report" height="420">
135135

0 commit comments

Comments
 (0)