Skip to content

Commit

Permalink
Update example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmintz committed Feb 26, 2024
1 parent cb0c375 commit 7c1bf93
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 79 deletions.
2 changes: 1 addition & 1 deletion examples/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GoogleTests(BaseCase):
def test_google_dot_com(self):
if self.headless and self._multithreaded:
self.open_if_not_url("about:blank")
print("Skipping test in headless multi-threaded mode.")
print("\n Skipping test in headless multi-threaded mode.")
self.skip("Skipping test in headless multi-threaded mode.")
self.open("https://google.com/ncr")
self.assert_title_contains("Google")
Expand Down
2 changes: 1 addition & 1 deletion examples/boilerplates/samples/test_page_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MyTests(BaseCase):
def test_page_objects(self):
if self.headless and self._multithreaded:
self.open_if_not_url("about:blank")
print("Skipping test in headless multi-threaded mode.")
print("\n Skipping test in headless multi-threaded mode.")
self.skip("Skipping test in headless multi-threaded mode.")
search_term = "SeleniumBase.io Docs"
expected_text = "SeleniumBase"
Expand Down
5 changes: 2 additions & 3 deletions examples/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ class GitHubTests(BaseCase):
def test_github(self):
if self.headless or self.page_load_strategy == "none":
self.open_if_not_url("about:blank")
message = "Unsupported mode for this test."
print("\n " + message)
self.skip(message)
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")
self.open("https://github.com/seleniumbase/SeleniumBase")
self.click_if_visible('[data-action="click:signup-prompt#dismiss"]')
self.highlight("div.Layout-main")
Expand Down
14 changes: 3 additions & 11 deletions examples/proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,10 @@

class ProxyTests(BaseCase):
def test_proxy(self):
if self.headless:
if self.headless or self.recorder_mode or self.browser == "safari":
self.open_if_not_url("about:blank")
print("Skipping test in Headless Mode.")
self.skip("Skipping test in Headless Mode.")
elif self.recorder_mode:
self.open_if_not_url("about:blank")
print("Skipping test in Recorder Mode.")
self.skip("Skipping test in Recorder Mode.")
elif self.browser == "safari":
self.open_if_not_url("about:blank")
print("Skipping test for using Safari.")
self.skip("Skipping test for using Safari.")
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")
settings.SKIP_JS_WAITS = True
if not self.page_load_strategy == "none" and not self.undetectable:
# This page takes too long to load otherwise
Expand Down
10 changes: 3 additions & 7 deletions examples/rate_limiting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ def print_item(self, item):
print(item)

def test_rate_limited_printing(self):
if self._multithreaded:
if self._multithreaded or self.recorder_mode:
self.open_if_not_url("about:blank")
print("Skipping test in multi-threaded mode.")
self.skip("Skipping test in multi-threaded mode.")
if self.recorder_mode:
self.open_if_not_url("about:blank")
print("Skipping test in Recorder Mode.")
self.skip("Skipping test in Recorder Mode.")
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")
message = "Running rate-limited print() on the command line"
self.open("data:text/html,<p>%s</p>" % message)
print("\n%s:" % message)
Expand Down
12 changes: 3 additions & 9 deletions examples/shadow_root_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@

class ShadowRootTest(BaseCase):
def test_shadow_root(self):
if self.recorder_mode:
if self.recorder_mode or not self.is_chromium():
self.open_if_not_url("about:blank")
message = "Skipping test in Recorder Mode."
print(message)
self.skip(message)
elif not self.is_chromium():
self.open_if_not_url("about:blank")
message = "This test is only for Chromium browsers!"
print(message)
self.skip(message)
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")
self.open("https://seleniumbase.io/other/shadow_dom")
print("")
self.click("button.tab_1")
Expand Down
18 changes: 6 additions & 12 deletions examples/test_apple_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ def test_apple_developer_site_webdriver_instructions(self):
self.demo_mode = True
self.demo_sleep = 0.5
self.message_duration = 2.0
if self.is_chromium() and not self.disable_csp:
self.get_new_driver(browser=self.browser, disable_csp=True)
if self.headless:
if self._multithreaded:
if self._multithreaded or self.undetectable or self.recorder_mode:
self.open_if_not_url("about:blank")
print("Skipping test in headless multi-threaded mode.")
self.skip("Skipping test in headless multi-threaded mode.")
elif self.undetectable:
self.open_if_not_url("about:blank")
print("Skipping test in headless undetectable mode.")
self.skip("Skipping test in headless undetectable mode.")
elif self.recorder_mode:
self.open_if_not_url("about:blank")
print("Skipping test in headless Recorder Mode.")
self.skip("Skipping test in headless Recorder Mode.")
elif self.browser == "chrome" or self.browser == "edge":
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")
elif self.is_chromium():
self.get_new_driver(browser=self.browser, headless2=True)
self.open("https://developer.apple.com/search/")
title = "Testing with WebDriver in Safari"
Expand Down
2 changes: 1 addition & 1 deletion examples/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_click_with_offset(self):
self.open("https://seleniumbase.io/canvas/")
if self.undetectable:
self.open_if_not_url("about:blank")
print("Skip this test in undetectable mode.")
print("\n Skip this test in undetectable mode.")
self.skip("Skip this test in undetectable mode.")
self.assert_title_contains("Canvas")
self.highlight("canvas")
Expand Down
3 changes: 1 addition & 2 deletions examples/test_chromedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

class ChromedriverTests(BaseCase):
def test_chromedriver_matches_chrome(self):
self.open("about:blank")
if self.browser != "chrome":
self.open_if_not_url("data:,")
print("\n This test is only for Chrome!")
print(' (Run with: "--browser=chrome")')
self.skip("This test is only for Chrome!")
chrome_version = self.get_chrome_version()
major_chrome_version = chrome_version.split(".")[0]
Expand Down
4 changes: 2 additions & 2 deletions examples/test_hack_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class HackingTests(BaseCase):
def test_hack_search(self):
if self.headless:
self.open_if_not_url("about:blank")
print("\n This test is not for Headless Mode.")
self.skip('Do not use "--headless" with this test.')
print("\n Skipping test in headless mode.")
self.skip('Skipping test in headless mode.')
self.open("https://google.com/ncr")
self.hide_elements("iframe")
self.assert_element('[title="Search"]')
Expand Down
5 changes: 2 additions & 3 deletions examples/test_multiple_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ class MultipleDriversTest(BaseCase):
def test_multiple_drivers(self):
if self.browser == "safari":
self.open_if_not_url("about:blank")
message = "Safari doesn't support multiple drivers."
print(message)
self.skip(message)
print("\n Safari doesn't support multiple drivers.")
self.skip("Safari doesn't support multiple drivers.")
self.open("data:text/html,<h1>Driver 1</h1>")
driver2 = self.get_new_driver()
self.open("data:text/html,<h1>Driver 2</h1>")
Expand Down
8 changes: 6 additions & 2 deletions examples/test_override_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class OverrideDriverTest(BaseCase):
def get_new_driver(self, *args, **kwargs):
"""This method overrides get_new_driver() from BaseCase."""
options = webdriver.ChromeOptions()
options.add_argument("--disable-3d-apis")
options.add_argument("--disable-notifications")
if self.headless:
options.add_argument("--headless=new")
Expand All @@ -24,4 +23,9 @@ def get_new_driver(self, *args, **kwargs):

def test_driver_override(self):
self.open("https://seleniumbase.io/demo_page")
self.assert_text("Demo Page", "h1")
self.type("#myTextInput", "This is Automated")
self.set_value("input#mySlider", "100")
self.select_option_by_text("#mySelect", "Set to 100%")
self.click("#checkBox1")
self.drag_and_drop("img#logo", "div#drop2")
self.click('button:contains("Click Me")')
18 changes: 17 additions & 1 deletion examples/test_override_sb_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ class BaseClass(BaseCase):
def get_new_driver(self, *args, **kwargs):
"""This method overrides get_new_driver() from BaseCase."""
options = webdriver.ChromeOptions()
options.add_argument("--disable-notifications")
if self.headless:
options.add_argument("--headless=new")
options.add_argument("--disable-gpu")
options.add_experimental_option(
"excludeSwitches", ["enable-automation"],
"excludeSwitches", ["enable-automation", "enable-logging"],
)
prefs = {
"credentials_enable_service": False,
"profile.password_manager_enabled": False,
}
options.add_experimental_option("prefs", prefs)
return webdriver.Chrome(options=options)

def setUp(self):
Expand Down Expand Up @@ -63,9 +69,19 @@ def tearDown(self):
def test_override_fixture_no_class(sb):
sb.open("https://seleniumbase.io/demo_page")
sb.type("#myTextInput", "This is Automated")
sb.set_value("input#mySlider", "100")
sb.select_option_by_text("#mySelect", "Set to 100%")
sb.click("#checkBox1")
sb.drag_and_drop("img#logo", "div#drop2")
sb.click('button:contains("Click Me")')


class TestOverride:
def test_override_fixture_inside_class(self, sb):
sb.open("https://seleniumbase.io/demo_page")
sb.type("#myTextInput", "This is Automated")
sb.set_value("input#mySlider", "100")
sb.select_option_by_text("#mySelect", "Set to 100%")
sb.click("#checkBox1")
sb.drag_and_drop("img#logo", "div#drop2")
sb.click('button:contains("Click Me")')
16 changes: 4 additions & 12 deletions examples/test_shadow_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ def download_tar_file_from_pypi(self, package):
return tar_file

def test_shadow_dom(self):
if self.browser != "chrome":
self.open("about:blank")
print("\n This test is for Google Chrome only!")
self.skip("This test is for Google Chrome only!")
if self.headless:
self.open("about:blank")
print("\n This test doesn't run in headless mode!")
self.skip("This test doesn't run in headless mode!")
if self.recorder_mode:
self.open("about:blank")
print("Skipping test in Recorder Mode.")
self.skip("Skipping test in Recorder Mode.")
if not self.browser == "chrome" or self.headless or self.recorder_mode:
self.open_if_not_url("about:blank")
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")

# Download Python package files from PyPI
file_name_1 = self.download_tar_file_from_pypi("sbase")
Expand Down
4 changes: 1 addition & 3 deletions examples/test_verify_chromedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

class ChromedriverTests(BaseCase):
def test_fail_if_versions_dont_match(self):
self.open("data:,")
self.open("about:blank")
if self.browser != "chrome":
self.open_if_not_url("data:,")
print("\n This test is only for Chrome!")
print(" (Run with: '--chrome')")
self.skip("This test is only for Chrome!")
chrome_version = self.get_chrome_version()
major_chrome_version = chrome_version.split(".")[0]
Expand Down
14 changes: 5 additions & 9 deletions examples/youtube_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
class YouTubeSearchTests(BaseCase):
def test_youtube_autocomplete_results(self):
"""Verify YouTube autocomplete search results."""
if self.headless:
if self.headless or self.browser == "safari":
self.open_if_not_url("about:blank")
message = "This test is skipped in headless mode."
print(message)
self.skip(message)
elif self.browser == "safari":
self.open_if_not_url("about:blank")
message = "This test is skipped when using Safari."
print(message)
self.skip(message)
print("\n Unsupported mode for this test.")
self.skip("Unsupported mode for this test.")
self.open("https://www.youtube.com/c/MichaelMintz")
search_term = "seleniumbase"
search_selector = "input#search"
result_selector = 'li[role="presentation"]'
self.click_if_visible('button[aria-label="Close"]')
self.double_click(search_selector)
self.sleep(0.15)
self.type(search_selector, search_term)
self.sleep(0.15)
# First verify that an autocomplete result exists
self.assert_element(result_selector)
top_result = self.get_text(result_selector)
Expand Down

0 comments on commit 7c1bf93

Please sign in to comment.