Skip to content

Commit 01669c9

Browse files
committed
Refactor examples
1 parent 5a151bf commit 01669c9

27 files changed

+105
-108
lines changed

examples/dialog_boxes/dialog_box_tour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_dialog_boxes(self):
5555
options = [("theme", "bootstrap"), ("width", "52%")]
5656
message = 'If the lowercase button text is "yes" or "no", '
5757
message += '<br><br>you can use the "Y" or "N" keys as shortcuts. '
58-
message += '<br><br><br>Other shortcuts include: <br><br>'
58+
message += "<br><br><br>Other shortcuts include: <br><br>"
5959
message += '"1": 1st button, "2": 2nd button, etc. Got it?'
6060
buttons = [("YES", "green"), ("NO", "red")]
6161
choice = self.get_jqc_button_input(message, buttons, options)

examples/github_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_github(self):
1414
self.get_new_driver(
1515
agent="""Mozilla/5.0 """
1616
"""AppleWebKit/537.36 (KHTML, like Gecko) """
17-
"""Chrome/Version 96.0.4664.55 Safari/537.36"""
17+
"""Chrome/Version 100.0.4896.88 Safari/537.36"""
1818
)
1919
self.open("https://github.com/search?q=SeleniumBase")
2020
self.slow_click('a[href="/seleniumbase/SeleniumBase"]')

examples/hack_the_planet.py

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ def test_all_your_base_are_belong_to_us(self):
2424
self.click_if_visible('button[aria-label="Close"]')
2525
self.set_text_content("h1#firstHeading", aybabtu)
2626
self.set_text_content("#ca-history a", aybabtu)
27-
self.set_text_content('#n-mainpage-description a', "ALL")
28-
self.set_text_content('#n-contents a', "YOUR")
29-
self.set_text_content('#n-currentevents a', "BASE")
30-
self.set_text_content('#n-randompage a', "ARE")
31-
self.set_text_content('#n-aboutsite a', "BELONG")
32-
self.set_text_content('#n-contactpage a', "TO")
33-
self.set_text_content('#n-sitesupport a', "US")
34-
self.set_text_content('.tocsection-1 span.toctext', "ALL")
35-
self.set_text_content('.tocsection-2 span.toctext', "YOUR")
36-
self.set_text_content('.tocsection-3 span.toctext', "BASE")
37-
self.set_text_content('.tocsection-4 span.toctext', "ARE")
38-
self.set_text_content('.tocsection-5 span.toctext', "BELONG")
39-
self.set_text_content('.tocsection-6 span.toctext', "TO")
40-
self.set_text_content('.tocsection-7 span.toctext', "US")
27+
self.set_text_content("#n-mainpage-description a", "ALL")
28+
self.set_text_content("#n-contents a", "YOUR")
29+
self.set_text_content("#n-currentevents a", "BASE")
30+
self.set_text_content("#n-randompage a", "ARE")
31+
self.set_text_content("#n-aboutsite a", "BELONG")
32+
self.set_text_content("#n-contactpage a", "TO")
33+
self.set_text_content("#n-sitesupport a", "US")
34+
self.set_text_content(".tocsection-1 span.toctext", "ALL")
35+
self.set_text_content(".tocsection-2 span.toctext", "YOUR")
36+
self.set_text_content(".tocsection-3 span.toctext", "BASE")
37+
self.set_text_content(".tocsection-4 span.toctext", "ARE")
38+
self.set_text_content(".tocsection-5 span.toctext", "BELONG")
39+
self.set_text_content(".tocsection-6 span.toctext", "TO")
40+
self.set_text_content(".tocsection-7 span.toctext", "US")
4141
self.highlight("h1#firstHeading", loops=2, scroll=False)
4242
self.highlight("#ca-history a", loops=2, scroll=False)
4343
self.highlight("nav#p-navigation", loops=2, scroll=False)
4444
self.highlight("div#toc", loops=2, scroll=False)
45-
self.highlight('.tocsection-1 span.toctext', loops=1, scroll=False)
46-
self.highlight('.tocsection-2 span.toctext', loops=1, scroll=False)
47-
self.highlight('.tocsection-3 span.toctext', loops=2, scroll=False)
48-
self.highlight('.tocsection-4 span.toctext', loops=1, scroll=False)
49-
self.highlight('.tocsection-5 span.toctext', loops=1, scroll=False)
50-
self.highlight('.tocsection-6 span.toctext', loops=1, scroll=False)
51-
self.highlight('.tocsection-7 span.toctext', loops=2, scroll=False)
52-
zoom_in = 'div.thumbinner{zoom: 1.4;-moz-transform: scale(1.4);}'
45+
self.highlight(".tocsection-1 span.toctext", loops=1, scroll=False)
46+
self.highlight(".tocsection-2 span.toctext", loops=1, scroll=False)
47+
self.highlight(".tocsection-3 span.toctext", loops=2, scroll=False)
48+
self.highlight(".tocsection-4 span.toctext", loops=1, scroll=False)
49+
self.highlight(".tocsection-5 span.toctext", loops=1, scroll=False)
50+
self.highlight(".tocsection-6 span.toctext", loops=1, scroll=False)
51+
self.highlight(".tocsection-7 span.toctext", loops=2, scroll=False)
52+
zoom_in = "div.thumbinner{zoom: 1.4;-moz-transform: scale(1.4);}"
5353
self.add_css_style(zoom_in)
5454
self.highlight("div.thumbinner", loops=8, scroll=False)
5555

@@ -82,7 +82,7 @@ def test_all_your_base_are_belong_to_us(self):
8282
self.set_text_content('a[href*="google.com/img"]', abtu)
8383
self.set_attributes('[value="Google Search"]', "value", ayb)
8484
self.set_attributes('[value="I\'m Feeling Lucky"]', "value", abtu)
85-
zoom_in = 'a{zoom: 1.2;-moz-transform: scale(1.2);}'
85+
zoom_in = "a{zoom: 1.2;-moz-transform: scale(1.2);}"
8686
self.add_css_style(zoom_in)
8787
zoom_in = (
8888
'[value="ALL YOUR BASE"]{zoom: 1.3;-moz-transform: scale(1.3);}'
@@ -104,36 +104,36 @@ def test_all_your_base_are_belong_to_us(self):
104104
self.highlight('a[href*="w/signup"]', loops=6, scroll=False)
105105

106106
self.open("https://www.youtube.com/")
107-
self.set_text_content('%s(1)' % yt_chip, "ALL")
108-
self.set_text_content('%s(2)' % yt_chip, "YOUR")
109-
self.set_text_content('%s(3)' % yt_chip, "BASE")
110-
self.set_text_content('%s(4)' % yt_chip, "ARE")
111-
self.set_text_content('%s(5)' % yt_chip, "BELONG")
112-
self.set_text_content('%s(6)' % yt_chip, "TO")
113-
self.set_text_content('%s(7)' % yt_chip, "US")
114-
self.set_text_content('%s(8)' % yt_chip, "!")
115-
self.set_text_content('%s(9)' % yt_chip, "!")
116-
self.set_text_content('%s(10)' % yt_chip, "!")
107+
self.set_text_content("%s(1)" % yt_chip, "ALL")
108+
self.set_text_content("%s(2)" % yt_chip, "YOUR")
109+
self.set_text_content("%s(3)" % yt_chip, "BASE")
110+
self.set_text_content("%s(4)" % yt_chip, "ARE")
111+
self.set_text_content("%s(5)" % yt_chip, "BELONG")
112+
self.set_text_content("%s(6)" % yt_chip, "TO")
113+
self.set_text_content("%s(7)" % yt_chip, "US")
114+
self.set_text_content("%s(8)" % yt_chip, "!")
115+
self.set_text_content("%s(9)" % yt_chip, "!")
116+
self.set_text_content("%s(10)" % yt_chip, "!")
117117
self.click_if_visible("#dismiss-button")
118118
self.click_if_visible('button[aria-label="Close"]')
119119
self.highlight("#scroll-container", loops=5, scroll=False)
120-
self.highlight('%s(1)' % yt_chip, loops=1, scroll=False)
121-
self.highlight('%s(2)' % yt_chip, loops=1, scroll=False)
122-
self.highlight('%s(3)' % yt_chip, loops=3, scroll=False)
123-
self.highlight('%s(4)' % yt_chip, loops=1, scroll=False)
124-
self.highlight('%s(5)' % yt_chip, loops=1, scroll=False)
125-
self.highlight('%s(6)' % yt_chip, loops=1, scroll=False)
126-
self.highlight('%s(7)' % yt_chip, loops=3, scroll=False)
120+
self.highlight("%s(1)" % yt_chip, loops=1, scroll=False)
121+
self.highlight("%s(2)" % yt_chip, loops=1, scroll=False)
122+
self.highlight("%s(3)" % yt_chip, loops=3, scroll=False)
123+
self.highlight("%s(4)" % yt_chip, loops=1, scroll=False)
124+
self.highlight("%s(5)" % yt_chip, loops=1, scroll=False)
125+
self.highlight("%s(6)" % yt_chip, loops=1, scroll=False)
126+
self.highlight("%s(7)" % yt_chip, loops=3, scroll=False)
127127
self.highlight("#scroll-container", loops=7, scroll=False)
128128

129129
self.open("https://github.com/features/actions")
130130
self.set_text_content('a[href="/team"]', ayb)
131131
self.set_text_content('a[href="/enterprise"]', abtu)
132-
self.set_text_content('h1 span:nth-child(1)', ayb)
133-
self.set_text_content('h1 span:nth-of-type(2)', "ARE")
134-
self.set_text_content('h1 span:nth-of-type(3)', "BELONG")
135-
self.set_text_content('h1 span:nth-of-type(4)', "TO")
136-
self.set_text_content('h1 span:nth-of-type(5)', "US")
132+
self.set_text_content("h1 span:nth-child(1)", ayb)
133+
self.set_text_content("h1 span:nth-of-type(2)", "ARE")
134+
self.set_text_content("h1 span:nth-of-type(3)", "BELONG")
135+
self.set_text_content("h1 span:nth-of-type(4)", "TO")
136+
self.set_text_content("h1 span:nth-of-type(5)", "US")
137137
self.type('input[name="q"]', aybabtu.lower())
138138
self.click("h1", scroll=False)
139139
self.highlight("nav", loops=5, scroll=False)
@@ -157,8 +157,8 @@ def test_all_your_base_are_belong_to_us(self):
157157
self.set_text_content('aside a[class*="tful"]:nth-child(4)', aybabtu)
158158
self.set_text_content('aside a[class*="tful"]:nth-child(5)', aybabtu)
159159
self.set_attribute("a.crayons-avatar img", "src", sb_dashboard_logo)
160-
self.set_text_content('.profile-preview-card button', "SeleniumBase")
161-
self.set_text_content('h2.crayons-story__title a', aybabtu)
160+
self.set_text_content(".profile-preview-card button", "SeleniumBase")
161+
self.set_text_content("h2.crayons-story__title a", aybabtu)
162162
self.type('input[name="q"]', aybabtu)
163163
self.highlight('input[name="q"]', loops=4, scroll=False)
164164
self.highlight('[aria-label="Primary sidebar"] div div', scroll=False)
@@ -180,12 +180,12 @@ def test_all_your_base_are_belong_to_us(self):
180180
self.highlight("h1", loops=6, scroll=False)
181181
self.highlight('a[aria-label*="Try PlayF"]', loops=4, scroll=False)
182182
self.highlight('a[aria-label*="Sign in to"]', loops=4, scroll=False)
183-
self.highlight('button#live-engage-btn', loops=6, scroll=False)
183+
self.highlight("button#live-engage-btn", loops=6, scroll=False)
184184

185185
self.open("https://www.snapchat.com/")
186186
self.set_text_content("h1", ayb)
187187
self.set_text_content("form .button-large span span", abtu)
188-
zoom_in = 'a.button-large span{zoom: 1.2;-moz-transform: scale(1.2);}'
188+
zoom_in = "a.button-large span{zoom: 1.2;-moz-transform: scale(1.2);}"
189189
self.add_css_style(zoom_in)
190190
self.highlight("h1", loops=6, scroll=False)
191191
self.highlight("form .button-large span span", loops=8, scroll=False)
@@ -201,7 +201,7 @@ def test_all_your_base_are_belong_to_us(self):
201201
self.set_text_content('span:contains("Labs")', "US")
202202
self.set_value("input#store_nav_search_term", ayb + " . . . .")
203203
self.highlight('div.content a[href*="help.steam"]', loops=6)
204-
self.highlight('#store_nav_area', loops=2, scroll=False)
204+
self.highlight("#store_nav_area", loops=2, scroll=False)
205205
self.highlight("#foryou_tab a", loops=1, scroll=False)
206206
self.highlight("#noteworthy_tab a", loops=3, scroll=False)
207207
self.highlight("#genre_tab a", loops=1, scroll=False)
@@ -222,7 +222,7 @@ def test_all_your_base_are_belong_to_us(self):
222222
self.remove_element('li:contains("What")')
223223
self.remove_element('li:contains("WI")')
224224
self.set_attributes("#news img", "src", sb_banner_logo)
225-
self.set_text_content('#ctitle', aybabtu)
225+
self.set_text_content("#ctitle", aybabtu)
226226
self.set_text_content('a[rel="prev"]', "All")
227227
self.set_text_content('a[href*="random"]', "Your")
228228
self.set_text_content('a[rel="next"]', "Base")
@@ -270,8 +270,8 @@ def test_all_your_base_are_belong_to_us(self):
270270
self.set_text_content('nav a[href="/partners/"]', "ARE")
271271
self.set_text_content('nav a[href="/community/"]', "BELONG")
272272
self.set_text_content('nav a[href="/case-studies/"]', "TO")
273-
self.set_text_content('nav #navbarDropdown', "US")
274-
self.set_text_content('nav #navbarDropdownMenuLink', ".")
273+
self.set_text_content("nav #navbarDropdown", "US")
274+
self.set_text_content("nav #navbarDropdownMenuLink", ".")
275275
if self.is_element_visible("h1"):
276276
self.set_text_content("h1", aybabtu)
277277
self.highlight("nav ul.navbar-nav", loops=3, scroll=False)
@@ -281,9 +281,9 @@ def test_all_your_base_are_belong_to_us(self):
281281
self.highlight('nav a[href="/partners/"]', loops=1, scroll=False)
282282
self.highlight('nav a[href="/community/"]', loops=1, scroll=False)
283283
self.highlight('nav a[href="/case-studies/"]', loops=1, scroll=False)
284-
self.highlight('nav #navbarDropdown', loops=2, scroll=False)
284+
self.highlight("nav #navbarDropdown", loops=2, scroll=False)
285285
if self.is_element_visible("h1"):
286-
self.highlight('h1', loops=6, scroll=False)
286+
self.highlight("h1", loops=6, scroll=False)
287287

288288
self.open("https://www.selenium.dev/")
289289
if self.is_element_visible('button[data-dismiss="alert"] span'):
@@ -298,7 +298,7 @@ def test_all_your_base_are_belong_to_us(self):
298298
self.set_text_content('li a:contains("English")', "US")
299299
self.set_text_content("div.lead", aybabtu)
300300
self.set_text_content("h2", aybabtu)
301-
zoom_in = 'div.lead{zoom: 1.25;-moz-transform: scale(1.25);}'
301+
zoom_in = "div.lead{zoom: 1.25;-moz-transform: scale(1.25);}"
302302
self.add_css_style(zoom_in)
303303
self.highlight("div#main_navbar", loops=1, scroll=False)
304304
self.highlight('li a:contains("ALL")', loops=1, scroll=False)
@@ -401,7 +401,7 @@ def test_all_your_base_are_belong_to_us(self):
401401

402402
self.open("https://pragprog.com/")
403403
self.set_text_content("header p", aybabtu)
404-
zoom_in = 'header p{zoom: 1.35;-moz-transform: scale(1.35);}'
404+
zoom_in = "header p{zoom: 1.35;-moz-transform: scale(1.35);}"
405405
self.add_css_style(zoom_in)
406406
self.highlight("header p", loops=10, scroll=False)
407407

examples/image_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class ImageTests(BaseCase):
77
@pytest.mark.run(order=1)
88
def test_pull_image_from_website(self):
9-
""" Pull an image from a website and save it as a PNG file. """
9+
"""Pull an image from a website and save it as a PNG file."""
1010
self.open("https://xkcd.com/1117/")
1111
selector = "#comic"
1212
file_name = "comic.png"
@@ -17,7 +17,7 @@ def test_pull_image_from_website(self):
1717

1818
@pytest.mark.run(order=2)
1919
def test_add_text_overlay_to_image(self):
20-
""" Add a text overlay to an image. """
20+
"""Add a text overlay to an image."""
2121
self.open("https://xkcd.com/1117/")
2222
selector = "#comic"
2323
file_name = "image_overlay.png"
@@ -31,7 +31,7 @@ def test_add_text_overlay_to_image(self):
3131

3232
@pytest.mark.run(order=3)
3333
def test_add_text_overlay_to_page_section(self):
34-
""" Add a text overlay to a section of a page. """
34+
"""Add a text overlay to a section of a page."""
3535
self.open("https://xkcd.com/2200/")
3636
selector = "#middleContainer"
3737
file_name = "section_overlay.png"
@@ -50,7 +50,7 @@ def test_add_text_overlay_to_page_section(self):
5050

5151
@pytest.mark.run(order=4)
5252
def test_add_text_overlay_to_full_page(self):
53-
""" Add a text overlay to a full page. """
53+
"""Add a text overlay to a full page."""
5454
self.open("https://xkcd.com/1922/")
5555
self.remove_element("#bottom")
5656
selector = "body"

examples/master_qa/basic_masterqa_test_0.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_masterqa(self):
77
self.highlight("div.mockup-wrapper")
88
self.verify("Do you see 4 computer devices?")
99
self.open("https://seleniumbase.io/demo_page")
10-
self.highlight('table')
10+
self.highlight("table")
1111
self.verify("Do you see elements in a table?")
1212
self.open("https://xkcd.com/1700/")
1313
self.highlight("#comic")

examples/swag_labs_suite.py

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

55
class SwagLabsTests(BaseCase):
66
def login_to_swag_labs(self, username="standard_user"):
7-
""" Login to Swag Labs and verify success. """
7+
"""Login to Swag Labs and verify success."""
88
url = "https://www.saucedemo.com"
99
self.open(url)
1010
if username not in self.get_text("#login_credentials"):

examples/test_agent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ def test_user_agent(self):
2323
print("\n--------------------------")
2424
try:
2525
self.driver.execute_cdp_cmd(
26-
"Network.setUserAgentOverride", {
26+
"Network.setUserAgentOverride",
27+
{
2728
"userAgent": "Mozilla/5.0 "
28-
"(Nintendo Switch; WifiWebAuthApplet) "
29-
"AppleWebKit/606.4 (KHTML, like Gecko) "
30-
"NF/6.0.1.15.4 NintendoBrowser/5.1.0.20393"
31-
}
29+
"(Nintendo Switch; WifiWebAuthApplet) "
30+
"AppleWebKit/606.4 (KHTML, like Gecko) "
31+
"NF/6.0.1.15.4 NintendoBrowser/5.1.0.20393"
32+
},
3233
)
3334
self.open("http://whatsmyuseragent.org/")
3435
user_agent_detected = self.get_text(".user-agent p")
@@ -38,7 +39,6 @@ def test_user_agent(self):
3839
finally:
3940
# Reset the user-agent back to the original
4041
self.driver.execute_cdp_cmd(
41-
"Network.setUserAgentOverride", {
42-
"userAgent": original_user_agent
43-
}
42+
"Network.setUserAgentOverride",
43+
{"userAgent": original_user_agent},
4444
)

examples/test_apple_site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_apple_developer_site_webdriver_instructions(self):
1919
title = "Testing with WebDriver in Safari"
2020
self.type('[placeholder*="developer.apple.com"]', title + "\n")
2121
self.click("link=%s" % title)
22-
self.assert_element('nav.documentation-nav')
22+
self.assert_element("nav.documentation-nav")
2323
self.assert_text(title, "h1")
2424
self.highlight("div.description div.abstract")
2525
self.highlight("h2")

examples/test_canvas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_pixel_colors(self):
1616
if self.is_chromium():
1717
return [color[0], color[1], color[2]]
1818
else:
19-
return [color['0'], color['1'], color['2']]
19+
return [color["0"], color["1"], color["2"]]
2020

2121
def test_canvas_actions(self):
2222
self.open("https://seleniumbase.io/canvas/")

examples/test_demo_site.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ def test_demo_site(self):
2222
# Verify that a hover dropdown link changes page text
2323
self.assert_text("Automation Practice", "h3")
2424
try:
25-
self.hover_and_click(
26-
"#myDropdown", "#dropOption2", timeout=2)
25+
self.hover_and_click("#myDropdown", "#dropOption2", timeout=1)
2726
except Exception:
28-
# If a human moves the mouse while the test runs
27+
# If someone moves the mouse while the test runs
2928
self.js_click("#dropOption2")
3029
self.assert_text("Link Two Selected", "h3")
3130

0 commit comments

Comments
 (0)