Skip to content

Commit

Permalink
[tda] speed up test_rageclick(), revert implicit wait increase (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
realkosty authored Sep 26, 2024
1 parent aa0187d commit c5ee451
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tda/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _sauce_browser(request, selenium_endpoint, se):
extra_params=urlencode({'se': se})
)

browser.implicitly_wait(20)
browser.implicitly_wait(10)

sentry_sdk.set_tag("sauceLabsUrl", f"https://app.saucelabs.com/tests/{browser.session_id}")

Expand Down
13 changes: 10 additions & 3 deletions tda/desktop_web/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from urllib.parse import urlencode
from conftest import CExp
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException


def test_checkout(desktop_web_driver, endpoints, batch_size, backend, random, sleep_length, cexp):
for endpoint in endpoints.react_endpoints:
Expand Down Expand Up @@ -35,10 +37,15 @@ def test_checkout(desktop_web_driver, endpoints, batch_size, backend, random, sl
desktop_web_driver.get(url)

try:
add_to_cart_btn = desktop_web_driver.find_element(By.CSS_SELECTOR, '.products-list button')
# Wait up to 2 implicit waits (should be 20 seconds)
try:
add_to_cart_btn = desktop_web_driver.find_element(By.CSS_SELECTOR, '.products-list button')
except TimeoutException as err:
add_to_cart_btn = desktop_web_driver.find_element(By.CSS_SELECTOR, '.products-list button')

for i in range(random.randrange(4) + 1):
add_to_cart_btn.click()
except Exception as err:
except TimeoutException as err:
sentry_sdk.metrics.incr(key="test_checkout.iteration.abandoned", value=1, tags=dict(query_string, reason=f"no_add_to_cart_btn({err.__class__.__name__})"))
continue

Expand All @@ -54,7 +61,7 @@ def test_checkout(desktop_web_driver, endpoints, batch_size, backend, random, sl
if (ce != CExp.ADD_TO_CART_JS_ERROR):
try:
desktop_web_driver.find_element(By.CSS_SELECTOR, 'a[href="/checkout"]').click()
except Exception as err:
except TimeoutException as err:
sentry_sdk.metrics.incr(key="test_checkout.iteration.abandoned", value=1, tags=dict(query_string, reason=f"no_proceed_to_checkout_btn({err.__class__.__name__})"))
continue

Expand Down
40 changes: 8 additions & 32 deletions tda/desktop_web/test_rageclick.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sentry_sdk
from urllib.parse import urlencode
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

# This many clicks to trigger rage click
# plus some extra for good measure (+ extra rage)
Expand Down Expand Up @@ -30,48 +31,23 @@ def test_rageclick(desktop_web_driver, endpoints, batch_size, backend, random, s
try:
desktop_web_driver.get(url)

# Optional - use the time.sleep here so button can rinish rendering before the desktop_web_driver tries to click it
# Solution - handle gracefully when the desktop_web_driver clicks a button that's not rendered yet, and then time.sleep(1) and try again
# time.sleep(5)
# Wait up to 2 implicit waits (should be 20 seconds)
try:
desktop_web_driver.find_element(By.CSS_SELECTOR, '.products-list button').click()
except TimeoutException as err:
desktop_web_driver.find_element(By.CSS_SELECTOR, '.products-list button').click()

buttonRendered = False
skips=0
while buttonRendered==False:
try:
if skips > 10:
sentry_sdk.capture_message("missed button more than 10 skips")
buttonRendered=True
add_to_cart_btn = desktop_web_driver.find_element(By.CSS_SELECTOR, '.products-list button')
time.sleep(2)
for i in range(random.randrange(4) + 1):
add_to_cart_btn.click()
buttonRendered=True
except Exception as err:
skips = skips + 1
sentry_sdk.capture_message("missed button handling %s skips gracefully" % (skips))
time.sleep(1)
pass

# Add 2 second sleep between the initial /products pageload
# and the navigation to the checkout cart
# to solve for web vitals issue as transaction may not be resolving
time.sleep(2)

desktop_web_driver.find_element(By.CSS_SELECTOR, '.show-desktop #top-right-links a[href="/cart"]').click()
time.sleep(sleep_length())
desktop_web_driver.find_element(By.CSS_SELECTOR, 'a[href="/checkout"]').click()
time.sleep(sleep_length())

# Rage click
checkout_button = desktop_web_driver.find_element(By.CSS_SELECTOR, '.complete-checkout-btn')
for _ in range(RAGE_CLICK_TRIGGER_QTY):
checkout_button.click()
time.sleep(8) #rageclick currently detected after 7 seconds
except Exception as err:
missedButtons = missedButtons + 1
sentry_sdk.set_tag("missedButtons", missedButtons)

if err:
sentry_sdk.capture_exception(err)
except Exception as err:
sentry_sdk.capture_exception(err)

time.sleep(sleep_length())

0 comments on commit c5ee451

Please sign in to comment.