Skip to content

Commit bb6a547

Browse files
committed
Update example tests
1 parent 1884e95 commit bb6a547

File tree

10 files changed

+56
-44
lines changed

10 files changed

+56
-44
lines changed

examples/basic_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Add an item to a shopping cart; verify; remove item; verify.
3-
"""
1+
"""Add an item to a shopping cart. Verify. Remove item. Verify."""
42
from seleniumbase import BaseCase
53

64

examples/offline_examples/test_demo_page.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import pytest
3-
from seleniumbase import version_tuple
43
from seleniumbase import BaseCase
54

65

@@ -12,10 +11,6 @@ def test_demo_page(self):
1211
file_path = dir_path + "/demo_page.html"
1312
self.load_html_file(file_path)
1413

15-
# Fail if the seleniumbase version is less than 4.0.0
16-
if version_tuple < (4, 0, 0):
17-
self.fail("This test requires seleniumbase>=4.0.0")
18-
1914
# Assert the title of the current web page
2015
self.assert_title("Web Testing Page")
2116

examples/presenter/core_presentation.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ def test_seleniumbase_chart(self):
1414
"<p>Basic API (test methods). Example test:</p>",
1515
code=(
1616
"from seleniumbase import BaseCase\n\n"
17-
"class MyTestClass(BaseCase):\n\n"
18-
" def test_basics(self):\n"
19-
' self.open("https://store.xkcd.com/search")\n'
20-
' self.type(\'input[name="q"]\', "xkcd book\\n")\n'
21-
' self.assert_text("xkcd book", "div.results")\n'
22-
' self.open("https://xkcd.com/353/")\n'
23-
" self.click('a[rel=\"license\"]')\n"
24-
" self.go_back()\n"
25-
' self.click_link("About")\n'
26-
' self.click_link("comic #249")\n'
27-
" self.assert_element('img[alt*=\"Chess\"]')\n"
17+
"class TestMFALogin(BaseCase):\n\n"
18+
" def test_mfa_login(self):\n"
19+
' self.open("seleniumbase.io/realworld/login")\n'
20+
' self.type("#username", "demo_user")\n'
21+
' self.type("#password", "secret_pass")\n'
22+
' self.enter_mfa_code('
23+
'"#totpcode", "GAXG2MTEOR3DMMDG")\n'
24+
' self.assert_text("Welcome!", "h1")\n'
25+
' self.highlight("img#image1")\n'
26+
" self.click('a:contains(\"This Page\")')\n"
27+
" self.save_screenshot_to_logs()\n"
28+
' self.click_link("Sign out")\n'
29+
' self.assert_element(\'a:contains("Sign in")\')\n'
2830
),
2931
)
3032
self.add_slide(
@@ -42,33 +44,36 @@ def test_seleniumbase_chart(self):
4244
"$ pytest test_suite.py --dashboard --html=report.html\n"
4345
"$ pytest github_test.py --demo --disable-csp\n"
4446
"$ pytest test_suite.py -n=2 --rs --crumbs\n"
45-
"$ pytest basic_test.py --incognito\n"
47+
"$ pytest test_demo_site.py --incognito\n"
48+
"$ pytest verify_undetected.py --uc\n"
49+
"$ pytest basic_test.py --sjw --pls=none\n"
4650
),
4751
)
4852
self.add_slide(
4953
"<p>The Console Scripts interface. Examples:</p>",
5054
code=(
51-
"$ sbase install chromedriver\n"
52-
"$ sbase install chromedriver latest\n"
55+
"$ sbase get chromedriver\n"
5356
"$ sbase mkdir new_test_folder\n"
5457
"$ sbase mkfile new_test.py\n"
58+
"$ sbase mkpres new_presentation.py\n"
59+
"$ sbase mkchart new_chart.py\n"
5560
"$ sbase print basic_test.py -n\n"
56-
"$ sbase translate basic_test.py -p --chinese -n\n"
57-
"$ sbase translate basic_test.py -p --japanese\n"
58-
"$ sbase translate basic_test.py -c --russian\n"
59-
"$ sbase download server\n"
61+
"$ sbase translate basic_test.py -p --ru -n\n"
6062
"$ sbase grid-hub start\n"
6163
'$ sbase grid-node start --hub="127.0.0.1"\n'
6264
"$ sbase grid-node stop\n"
6365
"$ sbase grid-hub stop\n"
66+
"$ sbase recorder\n"
67+
"$ sbase commander\n"
68+
"$ sbase methods\n"
6469
"$ sbase options\n"
6570
),
6671
)
6772
self.add_slide(
6873
'<p>Advanced API. "Presenter" example:</p>',
6974
code=(
7075
"from seleniumbase import BaseCase\n\n"
71-
"class MyPresenterClass(BaseCase):\n\n"
76+
"class MyPresenterClass(BaseCase):\n"
7277
" def test_presenter(self):\n"
7378
' self.create_presentation(theme="serif")\n'
7479
' self.add_slide("Welcome to Presenter!")\n'

examples/presenter/my_presentation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ def test_presenter(self):
4848
"from seleniumbase import BaseCase\n\n"
4949
"class MyTestClass(BaseCase):\n\n"
5050
" def test_basics(self):\n"
51-
' self.open("https://store.xkcd.com/search")\n'
52-
' self.type(\'input[name="q"]\', "xkcd book\\n")\n'
53-
' self.assert_text("xkcd: volume 0", "h3")\n'
5451
' self.open("https://xkcd.com/353/")\n'
5552
' self.assert_title("xkcd: Python")\n'
5653
" self.assert_element('img[alt=\"Python\"]')\n"
@@ -67,9 +64,14 @@ def test_presenter(self):
6764
"from seleniumbase import BaseCase\n\n"
6865
"<mark>class MyTestClass(BaseCase):</mark>\n\n"
6966
" def test_basics(self):\n"
70-
' self.open("https://store.xkcd.com/search")\n'
71-
' self.type(\'input[name="q"]\', "xkcd book\\n")\n'
72-
' self.assert_text("xkcd: volume 0", "h3")'
67+
' self.open("https://xkcd.com/353/")\n'
68+
' self.assert_title("xkcd: Python")\n'
69+
" self.assert_element('img[alt=\"Python\"]')\n"
70+
" self.click('a[rel=\"license\"]')\n"
71+
' self.assert_text("free to copy and reuse")\n'
72+
" self.go_back()\n"
73+
' self.click_link("About")\n'
74+
' self.assert_exact_text("xkcd.com", "h2")'
7375
),
7476
)
7577
self.add_slide(

examples/swag_labs_user_test.py renamed to examples/swag_labs_user_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def tearDown(self):
8181
self.save_teardown_screenshot() # Only if a test fails
8282
# Reset App State and Logout if the controls are present
8383
try:
84+
self.wait_for_ready_state_complete()
85+
if self.is_element_visible("#react-burger-menu-btn"):
86+
self.click("#react-burger-menu-btn")
87+
self.wait_for_element("a#reset_sidebar_link")
8488
self.js_click_if_present("a#reset_sidebar_link")
8589
self.js_click_if_present("a#logout_sidebar_link")
8690
except Exception:

examples/test_canvas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def get_pixel_colors(self):
2121

2222
def test_canvas_click_from_center(self):
2323
self.open("https://seleniumbase.io/other/canvas")
24-
self.click_with_offset("canvas", 0, 0, center=True)
25-
self.sleep(1) # Not needed (Lets you see the alert pop up)
24+
self.click_with_offset("canvas", 0, 0, mark=True, center=True)
25+
self.sleep(0.55) # Not needed (Lets you see the alert pop up)
2626
alert = self.switch_to_alert()
2727
self.assert_equal(alert.text, "You clicked on the square!")
2828
self.accept_alert()
29-
self.sleep(1) # Not needed (Lets you see the alert go away)
29+
self.sleep(0.55) # Not needed (Lets you see the alert go away)
3030

3131
def test_click_with_offset(self):
3232
self.open("https://seleniumbase.io/canvas/")

examples/test_docs_site.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
class DocsSiteTests(BaseCase):
55
def test_docs(self):
66
self.open("https://seleniumbase.io/examples/ReadMe/")
7-
self.assert_exact_text("Running Example Tests", "h1")
7+
self.assert_text("Running Example Tests", "h1")
88
self.js_click('a[href="../../help_docs/customizing_test_runs/"]')
9-
self.assert_exact_text("Command Line Options", "h1")
9+
self.assert_text("Command Line Options", "h1")
1010
self.js_click('a[href="../../examples/example_logs/ReadMe/"]')
11-
self.assert_exact_text("Dashboard / Reports", "h1")
11+
self.assert_text("Dashboard / Reports", "h1")
1212
self.js_click('a[href*="/seleniumbase/console_scripts/ReadMe/"]')
13-
self.assert_exact_text("Console Scripts", "h1")
13+
self.assert_text("Console Scripts", "h1")
1414
self.js_click('a[href="../../../help_docs/syntax_formats/"]')
15-
self.assert_exact_text("Syntax Formats", "h1")
15+
self.assert_text("Syntax Formats", "h1")
1616
self.js_click('a[href="../recorder_mode/"]')
17-
self.assert_exact_text("Recorder Mode", "h1")
17+
self.assert_text("Recorder Mode", "h1")
1818
self.js_click('a[href="../method_summary/"]')
19-
self.assert_exact_text("API Reference", "h1")
19+
self.assert_text("API Reference", "h1")
2020
self.click('img[alt="logo"]')
2121
self.assert_text("SeleniumBase", "h1")

examples/test_download_images.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class DownloadImages(BaseCase):
77
def test_download_images_directly(self):
8-
self.open("seleniumbase.io/examples/ReadMe/")
8+
self.open("https://seleniumbase.io/help_docs/chart_maker/")
99
img_elements_with_src = self.find_elements("img[src]")
1010
unique_src_values = []
1111
for img in img_elements_with_src:
@@ -35,6 +35,8 @@ def test_download_images_via_screenshot(self):
3535
count = 0
3636
for src in unique_src_values:
3737
self.open(src)
38+
if not self.headless and not self.headless2:
39+
self.highlight("img", loops=1)
3840
image = self.find_element("img")
3941
if src.startswith("data:") or ";base64" in src:
4042
# Special Cases: SVGs, etc. Convert to PNG.

examples/test_swag_labs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def tearDown(self):
6969
self.save_teardown_screenshot() # Only if a test fails
7070
# Reset App State and Logout if the controls are present
7171
try:
72+
self.wait_for_ready_state_complete()
73+
if self.is_element_visible("#react-burger-menu-btn"):
74+
self.click("#react-burger-menu-btn")
75+
self.wait_for_element("a#reset_sidebar_link")
7276
self.js_click_if_present("a#reset_sidebar_link")
7377
self.js_click_if_present("a#logout_sidebar_link")
7478
except Exception:

examples/visual_testing/layout_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
class VisualLayoutTests(BaseCase):
55
def test_applitools_layout_change(self):
66
self.open("https://applitools.com/helloworld?diff1")
7+
self.wait_for_element('a[href="?diff1"]')
78
print('\nCreating baseline in "visual_baseline" folder.')
89
self.check_window(name="helloworld", baseline=True)
910
# Click a button that changes the text of an element
1011
# (Text changes do not impact visual comparisons)
1112
self.click('a[href="?diff1"]')
13+
self.wait_for_ready_state_complete()
1214
# Verify html tags match the baseline
1315
self.check_window(name="helloworld", level=1)
1416
# Verify html tags and attribute names match the baseline

0 commit comments

Comments
 (0)