Skip to content

Commit d0c2d4e

Browse files
committed
Update example tests
1 parent 711312a commit d0c2d4e

File tree

5 files changed

+50
-32
lines changed

5 files changed

+50
-32
lines changed

examples/test_chinese_pdf.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
class ChinesePdfTests(BaseCase):
66
def test_chinese_pdf(self):
7-
8-
pdf = (
9-
"https://github.com/seleniumbase/SeleniumBase/"
10-
"files/3895614/unittest.pdf"
11-
)
7+
pdf = "https://seleniumbase.io/cdn/pdf/unittest_zh.pdf"
128

139
# Get and print PDF text
1410
pdf_text = self.get_pdf_text(pdf, page=2)

examples/wordle_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ class WordleTests(BaseCase):
1010
word_list = []
1111

1212
def initalize_word_list(self):
13-
js_file = "https://www.powerlanguage.co.uk/wordle/main.e65ce0a5.js"
14-
req_text = requests.get(js_file).text
15-
start = req_text.find("var La=") + len("var La=")
16-
end = req_text.find("],", start) + 1
17-
word_string = req_text[start:end]
13+
txt_file = "https://seleniumbase.io/cdn/txt/wordle_words.txt"
14+
word_string = requests.get(txt_file).text
1815
self.word_list = ast.literal_eval(word_string)
1916

2017
def modify_word_list(self, word, letter_status):

examples/youtube_search_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
class YouTubeSearchTests(BaseCase):
55
def test_youtube_autocomplete_results(self):
66
""" Verify YouTube autocomplete search results. """
7-
self.get_new_driver(block_images=True) # Runs faster
8-
self.open("https://www.youtube.com/")
7+
self.open("https://www.youtube.com/c/MichaelMintz")
98
search_term = "seleniumbase"
109
search_selector = "input#search"
1110
result_selector = 'li[role="presentation"] b'
@@ -25,8 +24,7 @@ def test_youtube_autocomplete_results(self):
2524

2625
def test_youtube_search_results(self):
2726
""" Verify finding a specific video by performing a YouTube search. """
28-
self.get_new_driver(block_images=True) # Runs faster
29-
self.open("https://www.youtube.com/")
27+
self.open("https://www.youtube.com/c/MichaelMintz")
3028
search_term = "SeleniumBase Common API Methods"
3129
search_selector = "input#search"
3230
self.type(search_selector, search_term + "\n")

integrations/node_js/my_first_test.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22

33

44
class MyTestClass(BaseCase):
5-
def test_basics(self):
6-
url = "https://store.xkcd.com/collections/posters"
7-
self.open(url)
8-
self.type('input[name="q"]', "xkcd book")
9-
self.click('input[value="Search"]')
10-
self.assert_text("xkcd: volume 0", "h3")
11-
self.open("https://xkcd.com/353/")
12-
self.assert_title("xkcd: Python")
13-
self.assert_element('img[alt="Python"]')
14-
self.click('a[rel="license"]')
15-
self.assert_text("free to copy and reuse")
16-
self.go_back()
17-
self.click_link("About")
18-
self.assert_exact_text("xkcd.com", "h2")
5+
def test_swag_labs(self):
6+
self.open("https://www.saucedemo.com")
7+
self.type("#user-name", "standard_user")
8+
self.type("#password", "secret_sauce\n")
9+
self.assert_element("#inventory_container")
10+
self.assert_text("PRODUCTS", "span.title")
11+
self.click('button[name*="backpack"]')
12+
self.click("#shopping_cart_container a")
13+
self.assert_text("YOUR CART", "span.title")
14+
self.assert_text("Backpack", "div.cart_item")
15+
self.click("button#checkout")
16+
self.type("#first-name", "SeleniumBase")
17+
self.type("#last-name", "Automation")
18+
self.type("#postal-code", "77123")
19+
self.click("input#continue")
20+
self.assert_text("CHECKOUT: OVERVIEW")
21+
self.assert_text("Backpack", "div.cart_item")
22+
self.click("button#finish")
23+
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
24+
self.assert_element('img[alt="Pony Express"]')
25+
self.js_click("a#logout_sidebar_link")

integrations/node_js/test_demo_site.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from seleniumbase import BaseCase
22

33

4-
class MyTestClass(BaseCase):
4+
class DemoSiteTests(BaseCase):
55
def test_demo_site(self):
66
self.open("https://seleniumbase.io/demo_page")
77

@@ -21,12 +21,17 @@ def test_demo_site(self):
2121

2222
# Verify that a hover dropdown link changes page text
2323
self.assert_text("Automation Practice", "h3")
24-
self.hover_and_click("#myDropdown", "#dropOption2")
24+
try:
25+
self.hover_and_click(
26+
"#myDropdown", "#dropOption2", timeout=2)
27+
except Exception:
28+
# If a human moves the mouse while the test runs
29+
self.js_click("#dropOption2")
2530
self.assert_text("Link Two Selected", "h3")
2631

2732
# Verify that a button click changes text on the page
2833
self.assert_text("This Text is Green", "#pText")
29-
self.click("#myButton")
34+
self.click('button:contains("Click Me")')
3035
self.assert_text("This Text is Purple", "#pText")
3136

3237
# Assert that the given SVG is visible on the page
@@ -60,9 +65,11 @@ def test_demo_site(self):
6065
self.assert_true(self.is_selected("#radioButton2"))
6166

6267
# Verify that clicking a checkbox makes it selected
68+
self.assert_element_not_visible("img#logo")
6369
self.assert_false(self.is_selected("#checkBox1"))
6470
self.click("#checkBox1")
6571
self.assert_true(self.is_selected("#checkBox1"))
72+
self.assert_element("img#logo")
6673

6774
# Verify clicking on multiple elements with one call
6875
self.assert_false(self.is_selected("#checkBox2"))
@@ -82,6 +89,11 @@ def test_demo_site(self):
8289
self.assert_true(self.is_selected(".fBox"))
8390
self.switch_to_default_content()
8491

92+
# Verify Drag and Drop
93+
self.assert_element_not_visible("div#drop2 img#logo")
94+
self.drag_and_drop("img#logo", "div#drop2")
95+
self.assert_element("div#drop2 img#logo")
96+
8597
# Assert link text
8698
self.assert_link_text("seleniumbase.com")
8799
self.assert_link_text("SeleniumBase on GitHub")
@@ -93,8 +105,16 @@ def test_demo_site(self):
93105
# Assert exact text
94106
self.assert_exact_text("Demo Page", "h1")
95107

108+
# Highlight a page element (Also asserts visibility)
109+
self.highlight("h2")
110+
111+
# Actions with Demo Mode enabled
112+
self.demo_mode = True
113+
self.type("input", "Have a Nice Day!")
114+
self.assert_text("SeleniumBase", "h2")
115+
96116
# Assert no broken links (Can be slow if many links)
97117
# self.assert_no_404_errors()
98118

99119
# Assert no JavaScript errors (Can also detect 404s)
100-
self.assert_no_js_errors()
120+
# self.assert_no_js_errors()

0 commit comments

Comments
 (0)