From 284a2124d7c4015d69a84f2937ac27e171a1011f Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 9 Nov 2023 19:58:57 -0500 Subject: [PATCH 1/4] Prevent internal WebDriver issue from disrupting tests --- seleniumbase/fixtures/base_case.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) 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() From b37c794e6f150d4f2d5b7eb974845aacd8309e10 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 9 Nov 2023 20:02:20 -0500 Subject: [PATCH 2/4] Refresh mkdocs dependencies --- mkdocs_build/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 301946eb030505422dbcee927939cd3c6ad98670 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 9 Nov 2023 20:30:05 -0500 Subject: [PATCH 3/4] Update example tests --- examples/parameterized_test.py | 1 + examples/raw_form_turnstile.py | 16 ++++++++-------- examples/raw_turnstile.py | 19 +++++++++++++++---- examples/test_coffee_cart.py | 4 ++++ examples/test_double_click.py | 2 ++ examples/test_get_coffee.py | 6 +++--- examples/visual_testing/layout_test.py | 4 ++-- 7 files changed, 35 insertions(+), 17 deletions(-) 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 From 7d176dd8c22235be2da4a99ffe85ecf71769bab6 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 9 Nov 2023 20:30:46 -0500 Subject: [PATCH 4/4] Version 4.21.1 --- seleniumbase/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"