Update examples
This commit is contained in:
parent
ae8cffac74
commit
a4c899472b
|
@ -7,8 +7,8 @@ class GoogleTests(BaseCase):
|
|||
def test_google_dot_com(self):
|
||||
self.open("https://google.com/ncr")
|
||||
self.sleep(0.5)
|
||||
self.hide_elements('iframe[name="callout"]')
|
||||
self.save_screenshot_to_logs() # ("./latest_logs" folder)
|
||||
self.sleep(0.5)
|
||||
self.type(HomePage.search_box, "github.com")
|
||||
self.assert_element(HomePage.search_button)
|
||||
self.assert_element(HomePage.feeling_lucky_button)
|
||||
|
|
|
@ -6,9 +6,12 @@ BaseCase.main(__name__, __file__)
|
|||
class GooglePage:
|
||||
def go_to_google(self, sb):
|
||||
sb.open("https://google.com/ncr")
|
||||
sb.remove_elements("iframe")
|
||||
sb.sleep(0.2)
|
||||
sb.hide_elements('iframe[name="callout"]') # Hide "Sign in" pop-up
|
||||
sb.sleep(0.1)
|
||||
|
||||
def do_search(self, sb, search_term):
|
||||
sb.click('input[title="Search"]')
|
||||
sb.type('input[title="Search"]', search_term + "\n")
|
||||
|
||||
def click_search_result(self, sb, content):
|
||||
|
|
|
@ -16,4 +16,4 @@ class MyChartMakerClass(BaseCase):
|
|||
self.add_data_point("Fri", 65)
|
||||
self.add_data_point("Sat", 50)
|
||||
self.add_slide("<p><b>Area Chart</b></p>" + self.extract_chart())
|
||||
self.begin_presentation(filename="line_chart.html", interval=8)
|
||||
self.begin_presentation(filename="line_chart.html", interval=4)
|
||||
|
|
|
@ -16,4 +16,4 @@ class MyChartMakerClass(BaseCase):
|
|||
self.add_data_point("Fri", 65)
|
||||
self.add_data_point("Sat", 50)
|
||||
self.add_slide("<p>Line Chart</p>" + self.extract_chart())
|
||||
self.begin_presentation(filename="line_chart.html", interval=8)
|
||||
self.begin_presentation(filename="line_chart.html", interval=4)
|
||||
|
|
|
@ -45,4 +45,4 @@ class MyChartMakerClass(BaseCase):
|
|||
self.add_data_point("Sat", 31)
|
||||
|
||||
self.add_slide("<p>Multi-Series Line Chart</p>" + self.extract_chart())
|
||||
self.begin_presentation(filename="multi_series_chart.html", interval=8)
|
||||
self.begin_presentation(filename="multi_series_chart.html", interval=4)
|
||||
|
|
|
@ -9,12 +9,12 @@ if __name__ == "__main__":
|
|||
class EdgeTests(BaseCase):
|
||||
def test_edge(self):
|
||||
if self.browser != "edge":
|
||||
self.open("about:blank")
|
||||
self.open_if_not_url("about:blank")
|
||||
print("\n This test is only for Microsoft Edge (Chromium)!")
|
||||
print(' (Run this test using "--edge" or "--browser=edge")')
|
||||
self.skip('Use "--edge" or "--browser=edge"')
|
||||
if self.headless:
|
||||
self.open("about:blank")
|
||||
elif self.headless:
|
||||
self.open_if_not_url("about:blank")
|
||||
print("\n This test is NOT designed for Headless Mode!")
|
||||
self.skip('Do NOT use "--headless" with this test!')
|
||||
self.open("edge://settings/help")
|
||||
|
|
|
@ -5,7 +5,7 @@ BaseCase.main(__name__, __file__)
|
|||
class GitHubTests(BaseCase):
|
||||
def test_github(self):
|
||||
if self.headless or self.page_load_strategy == "none":
|
||||
self.open_if_not_url("data:,")
|
||||
self.open_if_not_url("about:blank")
|
||||
message = "Unsupported mode for this test."
|
||||
print("\n " + message)
|
||||
self.skip(message)
|
||||
|
|
|
@ -15,3 +15,6 @@ class HandleAlertTests(BaseCase):
|
|||
self.assert_equal(alert.text, "My Prompt") # Not input field
|
||||
self.dismiss_alert()
|
||||
self.sleep(1) # Not needed (Lets you see the alert go away)
|
||||
if self.browser == "safari" and self._reuse_session:
|
||||
# Alerts can freeze Safari if reusing the browser session
|
||||
self.driver.quit()
|
||||
|
|
|
@ -17,3 +17,6 @@ class OfflineTests(BaseCase):
|
|||
self.assert_equal(alert.text, "My Prompt") # Not input field
|
||||
self.dismiss_alert()
|
||||
self.sleep(1) # Not needed (Lets you see the alert go away)
|
||||
if self.browser == "safari" and self._reuse_session:
|
||||
# Alerts can freeze Safari if reusing the browser session
|
||||
self.driver.quit()
|
||||
|
|
|
@ -6,13 +6,17 @@ BaseCase.main(__name__, __file__)
|
|||
class ProxyTests(BaseCase):
|
||||
def test_proxy(self):
|
||||
if self.headless:
|
||||
self.open("about:blank")
|
||||
self.open_if_not_url("about:blank")
|
||||
print("Skipping test in Headless Mode.")
|
||||
self.skip("Skipping test in Headless Mode.")
|
||||
if self.recorder_mode:
|
||||
self.open("about:blank")
|
||||
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.")
|
||||
settings.SKIP_JS_WAITS = True
|
||||
if not self.page_load_strategy == "none":
|
||||
# This page takes too long to load otherwise
|
||||
|
|
|
@ -11,11 +11,11 @@ class RateLimitingTests(BaseCase):
|
|||
|
||||
def test_rate_limited_printing(self):
|
||||
if self._multithreaded:
|
||||
self.open("data:,")
|
||||
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("data:,")
|
||||
self.open_if_not_url("about:blank")
|
||||
print("Skipping test in Recorder Mode.")
|
||||
self.skip("Skipping test in Recorder Mode.")
|
||||
message = "Running rate-limited print() on the command line"
|
||||
|
|
|
@ -7,9 +7,15 @@ BaseCase.main(__name__, __file__)
|
|||
class ShadowRootTest(BaseCase):
|
||||
def test_shadow_root(self):
|
||||
if self.recorder_mode:
|
||||
self.open("about:blank")
|
||||
print("Skipping test in Recorder Mode.")
|
||||
self.skip("Skipping test in Recorder Mode.")
|
||||
self.open_if_not_url("about:blank")
|
||||
message = "Skipping test in Recorder Mode."
|
||||
print(message)
|
||||
self.skip(message)
|
||||
elif self.browser == "safari":
|
||||
self.open_if_not_url("about:blank")
|
||||
message = "Skipping test for using Safari."
|
||||
print(message)
|
||||
self.skip(message)
|
||||
self.open("https://seleniumbase.io/other/shadow_dom")
|
||||
print("")
|
||||
self.click("button.tab_1")
|
||||
|
|
|
@ -10,15 +10,15 @@ class AppleTests(BaseCase):
|
|||
self.message_duration = 2.0
|
||||
if self.headless:
|
||||
if self._multithreaded:
|
||||
self.open("about:blank")
|
||||
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("about:blank")
|
||||
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("about:blank")
|
||||
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":
|
||||
|
|
|
@ -29,10 +29,15 @@ class CanvasTests(BaseCase):
|
|||
self.assert_equal(alert.text, "You clicked on the square!")
|
||||
self.accept_alert()
|
||||
self.sleep(0.55) # Not needed (Lets you see the alert go away)
|
||||
if self.browser == "safari" and self._reuse_session:
|
||||
# Alerts can freeze Safari if reusing the browser session
|
||||
self.driver.quit()
|
||||
|
||||
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.")
|
||||
self.skip("Skip this test in undetectable mode.")
|
||||
self.assert_title_contains("Canvas")
|
||||
self.highlight("canvas")
|
||||
|
|
|
@ -3,20 +3,21 @@
|
|||
set_attribute() -> Modifies the attribute of the first matching element.
|
||||
set_attributes() -> Modifies the attribute of all matching elements. """
|
||||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class HackingTests(BaseCase):
|
||||
def test_hack_search(self):
|
||||
if self.headless:
|
||||
self.open_if_not_url("data:,")
|
||||
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.')
|
||||
self.open("https://google.com/ncr")
|
||||
self.hide_elements("iframe")
|
||||
self.assert_element('input[title="Search"]')
|
||||
self.sleep(0.5)
|
||||
self.set_attribute('[action="/search"]', "action", "//bing.com/search")
|
||||
self.set_attributes('[value="Google Search"]', "value", "Bing Search")
|
||||
self.type('input[title="Search"]', "SeleniumBase GitHub Docs Install")
|
||||
self.type('input[title="Search"]', "GitHub SeleniumBase Docs Install")
|
||||
self.sleep(0.5)
|
||||
self.js_click('[value="Bing Search"]')
|
||||
self.highlight("h1.b_logo")
|
||||
|
|
|
@ -4,6 +4,11 @@ BaseCase.main(__name__, __file__)
|
|||
|
||||
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)
|
||||
self.open("data:text/html,<h1>Driver 1</h1>")
|
||||
driver2 = self.get_new_driver()
|
||||
self.open("data:text/html,<h1>Driver 2</h1>")
|
||||
|
|
|
@ -15,7 +15,7 @@ if __name__ == "__main__":
|
|||
class SkypeTests(BaseCase):
|
||||
def test_skype_mobile_site(self):
|
||||
if not self.mobile_emulator:
|
||||
self.open("data:,")
|
||||
self.open_if_not_url("about:blank")
|
||||
print("\n This test is only for mobile-device web browsers!")
|
||||
print(' (Use "--mobile" to run this test in Mobile Mode!)')
|
||||
self.skip('Use "--mobile" to run this test in Mobile Mode!')
|
||||
|
|
|
@ -6,26 +6,26 @@ BaseCase.main(__name__, __file__)
|
|||
|
||||
class MyTestSuite(BaseCase):
|
||||
def test_1(self):
|
||||
self.open("https://xkcd.com/1664/")
|
||||
self.assert_text("Mycology", "div#ctitle", timeout=4)
|
||||
self.open("https://xkcd.com/1722/")
|
||||
self.assert_text("Debugging", "div#ctitle", timeout=4)
|
||||
for p in range(3):
|
||||
self.click('a[rel="next"]')
|
||||
self.assert_text("Algorithms", "div#ctitle", timeout=4)
|
||||
self.assert_text("Linear Regression", "div#ctitle", timeout=4)
|
||||
|
||||
@pytest.mark.expected_failure
|
||||
def test_2(self):
|
||||
print("\n(This test should fail)")
|
||||
self.open("https://xkcd.com/1675/")
|
||||
raise Exception("FAKE EXCEPTION: This test fails on purpose.")
|
||||
self.open("https://xkcd.com/1373/")
|
||||
self.assert_text("FakeText", "div#ctitle", timeout=0.4)
|
||||
|
||||
def test_3(self):
|
||||
self.open("https://xkcd.com/1406/")
|
||||
self.assert_text("Universal Converter Box", "div#ctitle", timeout=4)
|
||||
self.open("https://xkcd.com/2224/")
|
||||
self.assert_text("Software Updates", "div#ctitle", timeout=4)
|
||||
self.open("https://xkcd.com/608/")
|
||||
self.assert_text("Form", "div#ctitle", timeout=4)
|
||||
self.assert_exact_text("Form", "div#ctitle", timeout=4)
|
||||
|
||||
@pytest.mark.expected_failure
|
||||
def test_4(self):
|
||||
print("\n(This test should fail)")
|
||||
self.open("https://xkcd.com/1670/")
|
||||
self.assert_element("FakeElement.DoesNotExist", timeout=0.5)
|
||||
self.open("https://xkcd.com/2224/")
|
||||
self.assert_element("FakeElement.DoesNotExist", timeout=0.4)
|
||||
|
|
|
@ -10,9 +10,9 @@ class TimeLimitTests(BaseCase):
|
|||
"""This test fails on purpose to show the runtime_limit() decorator
|
||||
for code blocks that run longer than the time limit specified."""
|
||||
print("\n(This test should fail)")
|
||||
self.open("https://xkcd.com/1190")
|
||||
with decorators.runtime_limit(0.5):
|
||||
self.sleep(0.75)
|
||||
self.open("https://xkcd.com/2511")
|
||||
with decorators.runtime_limit(0.7):
|
||||
self.sleep(0.95)
|
||||
|
||||
@pytest.mark.expected_failure
|
||||
def test_set_time_limit_method(self):
|
||||
|
@ -22,7 +22,7 @@ class TimeLimitTests(BaseCase):
|
|||
which is after pytest starts it's own internal clock for tests.
|
||||
Usage: (inside tests) => self.set_time_limit(SECONDS)
|
||||
Usage: (command-line) => --time-limit=SECONDS"""
|
||||
self.set_time_limit(2.5) # Fail test if time exceeds 2.5 seconds
|
||||
self.set_time_limit(2.2) # Fail test if time exceeds 2.2 seconds
|
||||
print("\n(This test should fail)")
|
||||
self.open("https://xkcd.com/1658")
|
||||
self.sleep(3)
|
||||
|
|
|
@ -51,6 +51,7 @@ class WordleTests(BaseCase):
|
|||
|
||||
def test_wordle(self):
|
||||
if self.headless:
|
||||
self.open_if_not_url("about:blank")
|
||||
self.skip("Skip this test in headless mode!")
|
||||
self.open("https://www.nytimes.com/games/wordle/index.html")
|
||||
self.click_if_visible('svg[data-testid="icon-close"]', timeout=2)
|
||||
|
|
|
@ -6,10 +6,15 @@ class YouTubeSearchTests(BaseCase):
|
|||
def test_youtube_autocomplete_results(self):
|
||||
"""Verify YouTube autocomplete search results."""
|
||||
if self.headless:
|
||||
self.open_if_not_url("data:,")
|
||||
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)
|
||||
self.open("https://www.youtube.com/c/MichaelMintz")
|
||||
search_term = "seleniumbase"
|
||||
search_selector = "input#search"
|
||||
|
|
Loading…
Reference in New Issue