Skip to content

Commit

Permalink
Merge pull request #2261 from seleniumbase/fix-internal-webdriver-issue
Browse files Browse the repository at this point in the history
Prevent internal WebDriver issue from disrupting tests
  • Loading branch information
mdmintz authored Nov 10, 2023
2 parents 62e7a04 + 7d176dd commit 2f5838d
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions examples/parameterized_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 8 additions & 8 deletions examples/raw_form_turnstile.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand Down
19 changes: 15 additions & 4 deletions examples/raw_turnstile.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions examples/test_coffee_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions examples/test_double_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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()"]')
self.assert_text("Hello World", "#demo")

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()"]')
Expand Down
6 changes: 3 additions & 3 deletions examples/test_get_coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions examples/visual_testing/layout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.21.0"
__version__ = "4.21.1"
22 changes: 17 additions & 5 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2f5838d

Please sign in to comment.