Skip to content

Commit e355356

Browse files
committed
Add unit tests
1 parent 03daf92 commit e355356

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

examples/unit_tests/ReadMe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### <img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="20" /> pytest-specific unit tests
2+
3+
The tests in this folder are for basic verification of the SeleniumBase framework with pytest.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
""" Run with pytest """
2+
3+
4+
def test_simple_cases(testdir):
5+
""" Verify a simple passing test and a simple failing test. """
6+
testdir.makepyfile(
7+
"""
8+
from seleniumbase import BaseCase
9+
class MyTestCase(BaseCase):
10+
def test_passing(self):
11+
self.assert_equal('yes', 'yes')
12+
def test_failing(self):
13+
self.assert_equal('yes', 'no')
14+
"""
15+
)
16+
result = testdir.inline_run("--headless", "--rs")
17+
assert result.matchreport("test_passing").passed
18+
assert result.matchreport("test_failing").failed
19+
20+
21+
def test_basecase(testdir):
22+
testdir.makepyfile(
23+
"""
24+
from seleniumbase import BaseCase
25+
class MyTest(BaseCase):
26+
def test_basecase(self):
27+
self.open("data:text/html,<p>Hello<br><input></p>")
28+
self.assert_element("html > body") # selector
29+
self.assert_text("Hello", "body p") # text, selector
30+
self.type("input", "Goodbye") # selector, text
31+
self.click("body p") # selector
32+
"""
33+
)
34+
result = testdir.inline_run("--headless")
35+
assert result.matchreport("test_basecase").passed
36+
37+
38+
def test_sb_fixture(testdir):
39+
testdir.makepyfile(
40+
"""
41+
def test_sb_fixture(sb):
42+
sb.open("data:text/html,<p>Hello<br><input></p>")
43+
sb.assert_element("html > body") # selector
44+
sb.assert_text("Hello", "body p") # text, selector
45+
sb.type("input", "Goodbye") # selector, text
46+
sb.click("body p") # selector
47+
"""
48+
)
49+
result = testdir.inline_run("--headless")
50+
assert result.matchreport("test_sb_fixture").passed
51+
52+
53+
def test_request_sb_fixture(testdir):
54+
testdir.makepyfile(
55+
"""
56+
def test_request_sb_fixture(request):
57+
sb = request.getfixturevalue('sb')
58+
sb.open("data:text/html,<p>Hello<br><input></p>")
59+
sb.assert_element("html > body") # selector
60+
sb.assert_text("Hello", "body p") # text, selector
61+
sb.type("input", "Goodbye") # selector, text
62+
sb.click("body p") # selector
63+
sb.tearDown()
64+
"""
65+
)
66+
result = testdir.inline_run("--headless")
67+
assert result.matchreport("test_request_sb_fixture").passed

0 commit comments

Comments
 (0)