Skip to content

Commit a5f1849

Browse files
committed
Update example tests
1 parent 796eee9 commit a5f1849

9 files changed

+157
-145
lines changed

examples/hack_the_planet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def test_all_your_base_are_belong_to_us(self):
88
ayb = "ALL YOUR BASE"
99
abtu = "ARE BELONG TO US"
1010
aybabtu = "%s %s" % (ayb, abtu)
11-
sb_banner_logo = "//seleniumbase.io/cdn/img/sb_logo_10.png"
12-
sb_dashboard_logo = "//seleniumbase.io/img/dash_pie_3.png"
11+
sb_banner_logo = "//seleniumbase.github.io/cdn/img/sb_logo_10.png"
12+
sb_dashboard_logo = "//seleniumbase.github.io/img/dash_pie_3.png"
1313
wiki = "https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us"
1414

1515
self.open(wiki)

examples/my_first_test.py

Lines changed: 118 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
A complete end-to-end test for an e-commerce website.
3-
"""
1+
"""A complete end-to-end test for an e-commerce website."""
42
from seleniumbase import BaseCase
53

64

@@ -29,115 +27,121 @@ def test_swag_labs(self):
2927
self.js_click("a#logout_sidebar_link")
3028
self.assert_element("div#login_button_container")
3129

32-
####
3330

34-
#######################################################################
35-
#
36-
# **** NOTES / USEFUL INFO ****
37-
#
38-
# 1. By default, page elements are identified by "css selector".
39-
# CSS Guide: "https://www.w3schools.com/cssref/css_selectors.asp".
40-
# Other selectors include: "link text", "partial link text", "name",
41-
# "class name", and "id", but most of those can be expressed as CSS.
42-
#
43-
# Here's an example of changing the "by":
44-
# [
45-
# self.click('Next', by="partial link text")
46-
# ]
47-
#
48-
# XPath is used by default if the arg starts with "/", "./", or "(":
49-
# [
50-
# self.click('/html/body/div[3]/div[4]/p[2]/a')
51-
# ]
52-
#
53-
# If you're completely new to CSS selectors, right-click on a
54-
# web page and select "Inspect" to see the CSS in the html.
55-
#
56-
# 2. Most methods have the optional "timeout" argument.
57-
# Here's an example of changing the "timeout":
58-
# [
59-
# self.assert_element('img[alt="Python"]', timeout=15)
60-
# ]
61-
# The "timeout" argument tells the method how many seconds to wait
62-
# for an element to appear before failing the test. This is
63-
# useful if a web page needs additional time to load an element.
64-
# If you don't specify a "timeout", a default timeout is used.
65-
# Default timeouts are configured in seleniumbase/config/settings.py
66-
#
67-
# 3. SeleniumBase methods often perform multiple actions. For example,
68-
# self.type(SELECTOR, TEXT) will do the following:
69-
# * Wait for the element to be visible
70-
# * Wait for the element to be interactive
71-
# * Clear the text field
72-
# * Type in the new text
73-
# * Press Enter/Return if the text ends in "\n": {element.submit()}
74-
#
75-
# 4. Duplicate method names may exist for the same method:
76-
# (This makes it easier to switch over from other test frameworks.)
77-
# Example:
78-
# self.open() = self.visit() = self.open_url() = self.goto()
79-
# self.type() = self.update_text() = self.input() = self.fill()
80-
# self.send_keys() = self.add_text()
81-
# self.get_element() = self.wait_for_element_present()
82-
# self.find_element() = self.wait_for_element_visible()
83-
# = self.wait_for_element()
84-
# self.assert_element() = self.assert_element_visible()
85-
# self.assert_text() = self.assert_text_visible()
86-
# self.find_text() = self.wait_for_text_visible()
87-
# = self.wait_for_text()
88-
# self.click_link("LinkText") = self.click("link=LinkText")
89-
# = self.click_link_text("LinkText")
90-
# = self.click('a:contains("LinkText")')
91-
# * self.get(url) is SPECIAL: *
92-
# If {url} is a valid URL, self.get() works just like self.open()
93-
# Otherwise {url} becomes a selector for calling self.get_element()
94-
#
95-
# 5. There's usually more than one way to do the same thing.
96-
# Example 1:
97-
# [
98-
# self.assert_text("xkcd: volume 0", "h3")
99-
# ]
100-
# Is the same as:
101-
# [
102-
# text = self.get_text("h3")
103-
# self.assert_true("xkcd: volume 0" in text)
104-
# ]
105-
# Is also the same as:
106-
# [
107-
# element = self.find_element("h3")
108-
# text = element.text
109-
# self.assert_true("xkcd: volume 0" in text)
110-
# ]
111-
#
112-
# Example 2:
113-
# [
114-
# self.assert_exact_text("xkcd.com", "h2")
115-
# ]
116-
# Is the same as:
117-
# [
118-
# text = self.get_text("h2").strip()
119-
# self.assert_true("xkcd.com".strip() == text)
120-
# ]
121-
#
122-
# Example 3:
123-
# [
124-
# title = self.get_attribute("#comic img", "title")
125-
# ]
126-
# Is the same as:
127-
# [
128-
# element = self.find_element("#comic img")
129-
# title = element.get_attribute("title")
130-
# ]
131-
#
132-
# 6. self.assert_exact_text(TEXT) ignores leading and trailing
133-
# whitespace in the TEXT assertion.
134-
# So, self.assert_exact_text("Some Text") will find [" Some Text "].
135-
#
136-
# 7. self.js_click(SELECTOR) can be used to click on hidden elements.
137-
#
138-
# 8. self.open(URL) will automatically complete URLs missing a prefix.
139-
# Example: google.com will become https://google.com before opened.
140-
#
141-
# 9. For the full method list, see one of the following:
142-
# * SeleniumBase/seleniumbase/fixtures/base_case.py
143-
# * SeleniumBase/help_docs/method_summary.md
31+
if __name__ == "__main__":
32+
from pytest import main
33+
main([__file__])
34+
35+
36+
#######################################################################
37+
#
38+
# **** NOTES / USEFUL INFO ****
39+
#
40+
# 1. By default, page elements are identified by "css selector".
41+
# CSS Guide: "https://www.w3schools.com/cssref/css_selectors.asp".
42+
# Other selectors include: "link text", "partial link text", "name",
43+
# "class name", and "id", but most of those can be expressed as CSS.
44+
#
45+
# Here's an example of changing the "by":
46+
# [
47+
# self.click('Next', by="partial link text")
48+
# ]
49+
#
50+
# XPath is used by default if the arg starts with "/", "./", or "(":
51+
# [
52+
# self.click('/html/body/div[3]/div[4]/p[2]/a')
53+
# ]
54+
#
55+
# If you're completely new to CSS selectors, right-click on a
56+
# web page and select "Inspect" to see the CSS in the html.
57+
#
58+
# 2. Most methods have the optional "timeout" argument.
59+
# Here's an example of changing the "timeout":
60+
# [
61+
# self.assert_element('img[alt="Python"]', timeout=15)
62+
# ]
63+
# The "timeout" argument tells the method how many seconds to wait
64+
# for an element to appear before failing the test. This is
65+
# useful if a web page needs additional time to load an element.
66+
# If you don't specify a "timeout", a default timeout is used.
67+
# Default timeouts are configured in seleniumbase/config/settings.py
68+
#
69+
# 3. SeleniumBase methods often perform multiple actions. For example,
70+
# self.type(SELECTOR, TEXT) will do the following:
71+
# * Wait for the element to be visible
72+
# * Wait for the element to be interactive
73+
# * Clear the text field
74+
# * Type in the new text
75+
# * Press Enter/Return if the text ends in "\n": {element.submit()}
76+
#
77+
# 4. Duplicate method names may exist for the same method:
78+
# (This makes it easier to switch over from other test frameworks.)
79+
# Example:
80+
# self.open() = self.visit() = self.open_url() = self.goto()
81+
# self.type() = self.update_text() = self.input() = self.fill()
82+
# self.send_keys() = self.add_text()
83+
# self.get_element() = self.wait_for_element_present()
84+
# self.find_element() = self.wait_for_element_visible()
85+
# = self.wait_for_element()
86+
# self.assert_element() = self.assert_element_visible()
87+
# self.assert_text() = self.assert_text_visible()
88+
# self.find_text() = self.wait_for_text_visible()
89+
# = self.wait_for_text()
90+
# self.click_link("LinkText") = self.click("link=LinkText")
91+
# = self.click_link_text("LinkText")
92+
# = self.click('a:contains("LinkText")')
93+
# * self.get(url) is SPECIAL: *
94+
# If {url} is a valid URL, self.get() works just like self.open()
95+
# Otherwise {url} becomes a selector for calling self.get_element()
96+
#
97+
# 5. There's usually more than one way to do the same thing.
98+
# Example 1:
99+
# [
100+
# self.assert_text("xkcd: volume 0", "h3")
101+
# ]
102+
# Is the same as:
103+
# [
104+
# text = self.get_text("h3")
105+
# self.assert_true("xkcd: volume 0" in text)
106+
# ]
107+
# Is also the same as:
108+
# [
109+
# element = self.find_element("h3")
110+
# text = element.text
111+
# self.assert_true("xkcd: volume 0" in text)
112+
# ]
113+
#
114+
# Example 2:
115+
# [
116+
# self.assert_exact_text("xkcd.com", "h2")
117+
# ]
118+
# Is the same as:
119+
# [
120+
# text = self.get_text("h2").strip()
121+
# self.assert_true("xkcd.com".strip() == text)
122+
# ]
123+
#
124+
# Example 3:
125+
# [
126+
# title = self.get_attribute("#comic img", "title")
127+
# ]
128+
# Is the same as:
129+
# [
130+
# element = self.find_element("#comic img")
131+
# title = element.get_attribute("title")
132+
# ]
133+
#
134+
# 6. self.assert_exact_text(TEXT) ignores leading and trailing
135+
# whitespace in the TEXT assertion.
136+
# So, self.assert_exact_text("Some Text") will find [" Some Text "].
137+
#
138+
# 7. self.js_click(SELECTOR) can be used to click on hidden elements.
139+
#
140+
# 8. self.open(URL) will automatically complete URLs missing a prefix.
141+
# Example: google.com will become https://google.com before opened.
142+
#
143+
# 9. For the full method list, see one of the following:
144+
# * SeleniumBase/seleniumbase/fixtures/base_case.py
145+
# * SeleniumBase/help_docs/method_summary.md
146+
#
147+
# 10. pytest.main([__file__]) lets you run with "python" (vs. "pytest")

examples/presenter/my_presentation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ def test_presenter(self):
99
)
1010
self.add_slide(
1111
"<h3>SeleniumBase Presenter</h3><br />\n"
12-
'<img width="240" src="https://seleniumbase.io/img/logo3a.png" />'
12+
'<img width="240" '
13+
'src="https://seleniumbase.github.io/img/logo3a.png" />'
1314
'<span style="margin:144px;" />'
14-
'<img src="https://seleniumbase.io/other/python_3d_logo.png" />'
15+
'<img '
16+
'src="https://seleniumbase.github.io/other/python_3d_logo.png" />'
1517
"<br /><br />\n<h4>Create presentations with <b>Python</b></h4>"
1618
)
1719
self.add_slide(
@@ -40,7 +42,7 @@ def test_presenter(self):
4042
)
4143
self.add_slide(
4244
"<h3>Add <b>images</b> to slides:</h3>",
43-
image="https://seleniumbase.io/other/seagulls.jpg",
45+
image="https://seleniumbase.github.io/other/seagulls.jpg",
4446
)
4547
self.add_slide(
4648
"<h3>Add <b>code</b> to slides:</h3>",
@@ -125,7 +127,7 @@ def test_presenter(self):
125127
)
126128
self.add_slide(
127129
"<h2><b>The End</b></h2>",
128-
image="https://seleniumbase.io/img/sb_logo_10.png",
130+
image="https://seleniumbase.github.io/img/sb_logo_10.png",
129131
)
130132
self.begin_presentation(
131133
filename="presenter.html", show_notes=True, interval=0

examples/test_demo_site.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,8 @@ def test_demo_site(self):
115115
self.demo_mode = True
116116
self.type("input", "Have a Nice Day!")
117117
self.assert_text("SeleniumBase", "h2")
118+
119+
120+
if __name__ == "__main__":
121+
from pytest import main
122+
main([__file__])

examples/test_download_images.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ def test_download_images_via_screenshot(self):
4949
image.screenshot(file_path)
5050
self.assert_downloaded_file(filename)
5151
self._print(file_path)
52+
53+
54+
if __name__ == "__main__":
55+
from pytest import main
56+
main([__file__])

examples/test_override_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_new_driver(self, *args, **kwargs):
99
options.add_argument("--disable-3d-apis")
1010
options.add_argument("--disable-notifications")
1111
if self.headless:
12-
options.add_argument("--headless")
12+
options.add_argument("--headless=chrome")
1313
options.add_argument("--disable-gpu")
1414
options.add_experimental_option(
1515
"excludeSwitches", ["enable-automation", "enable-logging"],

examples/test_override_sb_fixture.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,37 @@
44

55
@pytest.fixture()
66
def sb(request):
7-
import sys
87
from selenium import webdriver
98
from seleniumbase import BaseCase
109

1110
class BaseClass(BaseCase):
12-
def setUp(self):
13-
super(BaseClass, self).setUp()
14-
15-
def tearDown(self):
16-
self.save_teardown_screenshot()
17-
super(BaseClass, self).tearDown()
18-
19-
def base_method(self):
20-
pass
21-
2211
def get_new_driver(self, *args, **kwargs):
2312
"""This method overrides get_new_driver() from BaseCase."""
2413
options = webdriver.ChromeOptions()
25-
if "linux" in sys.platform:
14+
if self.headless:
2615
options.add_argument("--headless=chrome")
16+
options.add_argument("--disable-gpu")
2717
options.add_experimental_option(
2818
"excludeSwitches", ["enable-automation"],
2919
)
3020
return webdriver.Chrome(options=options)
3121

32-
if request.cls:
33-
request.cls.sb = BaseClass("base_method")
34-
request.cls.sb.setUp()
35-
yield request.cls.sb
36-
request.cls.sb.tearDown()
37-
else:
38-
sb = BaseClass("base_method")
39-
sb.setUp()
40-
yield sb
41-
sb.tearDown()
22+
def setUp(self):
23+
super(BaseClass, self).setUp()
24+
25+
def base_method(self):
26+
pass
27+
28+
def tearDown(self):
29+
self.save_teardown_screenshot()
30+
super(BaseClass, self).tearDown()
31+
32+
sb = BaseClass("base_method")
33+
sb.setUpClass()
34+
sb.setUp()
35+
yield sb
36+
sb.tearDown()
37+
sb.tearDownClass()
4238

4339

4440
def test_override_fixture_no_class(sb):

examples/test_parse_soup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_beautiful_soup_and_tinymce(self):
2424
self.switch_to_default_content()
2525
self.click("button i.mce-i-image")
2626
self.type('input[aria-label="Width"].mce-textbox', "300")
27-
image_url = "https://seleniumbase.io/img/sb_logo_10.png"
27+
image_url = "https://seleniumbase.github.io/img/sb_logo_10.png"
2828
self.type("input.mce-textbox", image_url + "\n")
2929
self.switch_to_frame("iframe")
3030
self.click("h2")

examples/test_tinymce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def test_tinymce(self):
1818
self.type("input.mce-textbox", image_url + "\n")
1919
self.switch_to_frame("iframe")
2020
self.click("h2")
21-
self.switch_to_default_content()
2221
self.post_message("Automate anything with SeleniumBase!")
22+
self.switch_to_default_content()
2323
self.click('span:contains("File")')
2424
self.click('span:contains("Preview")')
2525
self.switch_to_frame('iframe[sandbox="allow-scripts"]')

0 commit comments

Comments
 (0)