Skip to content

Commit 1877302

Browse files
committed
Add and update example tests
1 parent 5032aaf commit 1877302

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

examples/basic_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
Same as my_first_test.py, but without the asserts.
3-
"""
4-
51
from seleniumbase import BaseCase
62

73

@@ -10,7 +6,10 @@ class MyTestClass(BaseCase):
106
def test_basic(self):
117
self.open("https://store.xkcd.com/search")
128
self.type('input[name="q"]', "xkcd book\n")
9+
self.assert_text("xkcd book", "div.results")
1310
self.open("https://xkcd.com/353/")
1411
self.click('a[rel="license"]')
1512
self.go_back()
1613
self.click_link_text("About")
14+
self.click_link_text("comic #249")
15+
self.assert_element('img[alt*="Chess"]')

examples/my_first_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class MyTestClass(BaseCase):
55

66
def test_basic(self):
77
self.open("https://store.xkcd.com/search")
8-
self.type('input[name="q"]', "xkcd book\n")
8+
self.type('input[name="q"]', "xkcd book")
9+
self.click('input[value="Search"]')
910
self.assert_text("xkcd: volume 0", "h3")
1011
self.open("https://xkcd.com/353/")
1112
self.assert_title("xkcd: Python")
@@ -15,6 +16,8 @@ def test_basic(self):
1516
self.go_back()
1617
self.click_link_text("About")
1718
self.assert_exact_text("xkcd.com", "h2")
19+
self.click_link_text("geohashing")
20+
self.assert_element("#comic img")
1821

1922
####
2023

examples/nth_child_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class NthChildSelectorTests(BaseCase):
5+
6+
def test_locate_rows_with_colors(self):
7+
self.open("https://xkcd.com/color/rgb/")
8+
tbody = "center > table tbody"
9+
self.demo_mode = True
10+
self.highlight(tbody)
11+
self.post_message("Part 1: Assert text in given row.")
12+
self.assert_text("teal", "tr:nth-child(2)")
13+
self.assert_text("aqua", "tr:nth-child(4)")
14+
self.assert_text("mint", "tr:nth-child(14)")
15+
self.assert_text("jade", "tr:nth-child(36)")
16+
soup = self.get_beautiful_soup(self.get_page_source())
17+
self.post_message("Part 2: Find row with given text.")
18+
self.locate_first_row_with_color("rust", tbody, soup)
19+
self.locate_first_row_with_color("azure", tbody, soup)
20+
self.locate_first_row_with_color("topaz", tbody, soup)
21+
22+
def locate_first_row_with_color(self, color, tbody, soup):
23+
rows = soup.body.table.find_all("tr")
24+
num_rows = len(rows)
25+
for row in range(num_rows):
26+
row_selector = tbody + " tr:nth-child(%s)" % (row + 1)
27+
if color in rows[row].text:
28+
message = '"%s" found on row %s' % (color, row + 1)
29+
self.post_message_and_highlight(message, row_selector)
30+
return # Found row and done
31+
self.post_error_message(
32+
'"%s" could not be found on any row!' % color)

0 commit comments

Comments
 (0)