diff --git a/examples/parameterized_test.py b/examples/parameterized_test.py index 84b2babe60d..fe8ddaffda1 100644 --- a/examples/parameterized_test.py +++ b/examples/parameterized_test.py @@ -13,6 +13,7 @@ class SearchTests(BaseCase): ) def test_parameterized_search(self, search_term, keyword, title_text): self.open("https://seleniumbase.io/help_docs/how_it_works/") + self.assert_title_contains("SeleniumBase Docs") self.type('input[aria-label="Search"]', search_term) self.click('mark:contains("%s")' % keyword) self.assert_title_contains(title_text) diff --git a/examples/raw_form_turnstile.py b/examples/raw_form_turnstile.py index 14e6a7a59c8..d2f639eedb4 100644 --- a/examples/raw_form_turnstile.py +++ b/examples/raw_form_turnstile.py @@ -1,6 +1,12 @@ from seleniumbase import SB +def open_the_form_turnstile_page(sb): + sb.driver.uc_open_with_reconnect( + "https://seleniumbase.io/apps/form_turnstile", reconnect_time=2.27, + ) + + def click_turnstile_and_verify(sb): sb.driver.reconnect(0.1) iframe = sb.driver.find_element("iframe") @@ -11,17 +17,11 @@ def click_turnstile_and_verify(sb): with SB(uc=True, test=True) as sb: - sb.driver.uc_open_with_reconnect( - "https://seleniumbase.io/apps/form_turnstile", - reconnect_time=2.33, - ) + open_the_form_turnstile_page(sb) try: click_turnstile_and_verify(sb) except Exception: - sb.driver.uc_open_with_reconnect( - "https://seleniumbase.io/apps/form_turnstile", - reconnect_time=2.33, - ) + open_the_form_turnstile_page(sb) click_turnstile_and_verify(sb) sb.press_keys("#name", "SeleniumBase") sb.press_keys("#email", "test@test.test") diff --git a/examples/raw_turnstile.py b/examples/raw_turnstile.py index 8a8da675463..8411a78e597 100644 --- a/examples/raw_turnstile.py +++ b/examples/raw_turnstile.py @@ -1,16 +1,27 @@ from seleniumbase import SB -with SB(uc=True, test=True) as sb: + +def open_the_turnstile_page(sb): sb.driver.uc_open_with_reconnect( - "https://seleniumbase.io/apps/turnstile", - reconnect_time=2.33, + "https://seleniumbase.io/apps/turnstile", reconnect_time=2.27, ) + + +def click_turnstile_and_verify(sb): sb.driver.reconnect(0.1) iframe = sb.driver.find_element("iframe") sb.driver.reconnect(0.5) sb.driver.switch_to.frame(iframe) sb.driver.uc_click("span.mark") - sb.switch_to_default_content() sb.assert_element("img#captcha-success", timeout=3.33) + + +with SB(uc=True, test=True) as sb: + open_the_turnstile_page(sb) + try: + click_turnstile_and_verify(sb) + except Exception: + open_the_turnstile_page(sb) + click_turnstile_and_verify(sb) sb.set_messenger_theme(location="top_left") sb.post_message("Selenium wasn't detected!", duration=3) diff --git a/examples/test_coffee_cart.py b/examples/test_coffee_cart.py index dd6ac896dd7..0add8fe2456 100644 --- a/examples/test_coffee_cart.py +++ b/examples/test_coffee_cart.py @@ -7,9 +7,13 @@ class CoffeeCartTest(BaseCase): def test_coffee_cart(self): self.open("https://seleniumbase.io/coffee/") self.assert_title("Coffee Cart") + self.assert_element('button:contains("Total: $0.00")') self.click('div[data-sb="Cappuccino"]') + self.assert_exact_text("cart (1)", 'a[aria-label="Cart page"]') self.click('div[data-sb="Flat-White"]') + self.assert_exact_text("cart (2)", 'a[aria-label="Cart page"]') self.click('div[data-sb="Cafe-Latte"]') + self.assert_exact_text("cart (3)", 'a[aria-label="Cart page"]') self.click('a[aria-label="Cart page"]') self.assert_exact_text("Total: $53.00", "button.pay") self.click("button.pay") diff --git a/examples/test_double_click.py b/examples/test_double_click.py index abf4a66364e..e893178fc19 100644 --- a/examples/test_double_click.py +++ b/examples/test_double_click.py @@ -6,6 +6,7 @@ class DoubleClickTests(BaseCase): def test_switch_to_frame_and_double_click(self): self.open("https://seleniumbase.io/w3schools/double_click") + self.assert_title("Double Click Testing") self.click("button#runbtn") self.switch_to_frame("iframe#iframeResult") self.double_click('[ondblclick="myFunction()"]') @@ -13,6 +14,7 @@ def test_switch_to_frame_and_double_click(self): def test_switch_to_frame_of_element_and_double_click(self): self.open("https://seleniumbase.io/w3schools/double_click") + self.assert_title("Double Click Testing") self.click("button#runbtn") self.switch_to_frame_of_element('[ondblclick="myFunction()"]') self.double_click('[ondblclick="myFunction()"]') diff --git a/examples/test_get_coffee.py b/examples/test_get_coffee.py index 2594040e802..141e8ecfae5 100644 --- a/examples/test_get_coffee.py +++ b/examples/test_get_coffee.py @@ -7,12 +7,12 @@ class GetCoffeeTest(BaseCase): def test_get_coffee(self): self.open("https://seleniumbase.io/coffee/") self.assert_title("Coffee Cart") - self.assert_link_text("cart (0)") - self.assert_element('[data-sb="Mocha"]') + self.assert_exact_text("cart (0)", 'a[aria-label="Cart page"]') + self.assert_element('div[data-sb="Mocha"]') self.click('div[data-sb="Mocha"]') self.assert_link_text("cart (1)") self.click_link_text("cart (1)") - self.assert_exact_text("Total: $8.00", ".pay") + self.assert_exact_text("Total: $8.00", "button.pay") self.click("button.pay") self.type("input#name", "Selenium Coffee") self.type("input#email", "test@test.test") diff --git a/examples/visual_testing/layout_test.py b/examples/visual_testing/layout_test.py index d57ccdf51e7..c5fe036db27 100644 --- a/examples/visual_testing/layout_test.py +++ b/examples/visual_testing/layout_test.py @@ -8,13 +8,13 @@ def test_applitools_layout_change(self): self.open("https://applitools.com/helloworld/?diff1") self.wait_for_element('a[href="?diff1"]') print('\nCreating baseline in "visual_baseline" folder.') - self.sleep(0.06) + self.sleep(0.08) self.check_window(name="helloworld", baseline=True) # Click a button that changes the text of an element # (Text changes do not impact visual comparisons) self.sleep(0.06) self.click('a[href="?diff1"]') - self.sleep(0.06) + self.sleep(0.14) # Verify html tags match the baseline self.check_window(name="helloworld", level=1) # Verify html tags and attribute names match the baseline diff --git a/mkdocs_build/requirements.txt b/mkdocs_build/requirements.txt index 5a0b08440ad..e23a4f5e6cf 100644 --- a/mkdocs_build/requirements.txt +++ b/mkdocs_build/requirements.txt @@ -4,7 +4,7 @@ regex>=2023.10.3 PyYAML>=6.0.1 pymdown-extensions>=10.3.1 -pipdeptree>=2.13.0 +pipdeptree>=2.13.1 python-dateutil>=2.8.2 Markdown==3.5.1 markdown2==2.4.10 diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index 3384786b8e1..f738015ba0e 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.21.0" +__version__ = "4.21.1" diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index 4195428da73..fbad650b0ff 100644 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -321,11 +321,23 @@ def open(self, url): self.driver.get(url) else: raise - if ( - self.driver.current_url == pre_action_url - and pre_action_url != url - ): - time.sleep(0.1) # Make sure load happens + try: + if ( + self.driver.current_url == pre_action_url + and pre_action_url != url + ): + time.sleep(0.1) # Make sure load happens + except Exception: + time.sleep(0.1) # First see if waiting helps + try: + self._check_browser() + if not self.driver.current_url: + raise Exception("No current URL!") + except Exception: + # Spin up a new driver with the URL + self.driver = self.get_new_driver() + self.driver.get(url) + self._check_browser() if settings.WAIT_FOR_RSC_ON_PAGE_LOADS: if not self.undetectable: self.wait_for_ready_state_complete()