Skip to content

Commit

Permalink
Browser Steps - Increasing timeout for actions and unifying timeout v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
dgtlmoon committed Feb 10, 2025
1 parent a8b3918 commit 5d93806
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions changedetectionio/blueprint/browser_steps/browser_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class steppable_browser_interface():
page = None
start_url = None

action_timeout = 10 * 1000

def __init__(self, start_url):
self.start_url = start_url

Expand Down Expand Up @@ -102,7 +104,7 @@ def action_click_element_containing_text(self, selector=None, value=''):
return
elem = self.page.get_by_text(value)
if elem.count():
elem.first.click(delay=randint(200, 500), timeout=3000)
elem.first.click(delay=randint(200, 500), timeout=self.action_timeout)

def action_click_element_containing_text_if_exists(self, selector=None, value=''):
logger.debug("Clicking element containing text if exists")
Expand All @@ -111,15 +113,15 @@ def action_click_element_containing_text_if_exists(self, selector=None, value=''
elem = self.page.get_by_text(value)
logger.debug(f"Clicking element containing text - {elem.count()} elements found")
if elem.count():
elem.first.click(delay=randint(200, 500), timeout=3000)
elem.first.click(delay=randint(200, 500), timeout=self.action_timeout)
else:
return

def action_enter_text_in_field(self, selector, value):
if not len(selector.strip()):
return

self.page.fill(selector, value, timeout=10 * 1000)
self.page.fill(selector, value, timeout=self.action_timeout)

def action_execute_js(self, selector, value):
response = self.page.evaluate(value)
Expand All @@ -130,15 +132,15 @@ def action_click_element(self, selector, value):
if not len(selector.strip()):
return

self.page.click(selector=selector, timeout=30 * 1000, delay=randint(200, 500))
self.page.click(selector=selector, timeout=self.action_timeout + 20 * 1000, delay=randint(200, 500))

def action_click_element_if_exists(self, selector, value):
import playwright._impl._errors as _api_types
logger.debug("Clicking element if exists")
if not len(selector.strip()):
return
try:
self.page.click(selector, timeout=10 * 1000, delay=randint(200, 500))
self.page.click(selector, timeout=self.action_timeout, delay=randint(200, 500))
except _api_types.TimeoutError as e:
return
except _api_types.Error as e:
Expand Down Expand Up @@ -185,10 +187,10 @@ def action_press_page_down(self, selector, value):
self.page.keyboard.press("PageDown", delay=randint(200, 500))

def action_check_checkbox(self, selector, value):
self.page.locator(selector).check(timeout=1000)
self.page.locator(selector).check(timeout=self.action_timeout)

def action_uncheck_checkbox(self, selector, value):
self.page.locator(selector).uncheck(timeout=1000)
self.page.locator(selector).uncheck(timeout=self.action_timeout)


# Responsible for maintaining a live 'context' with the chrome CDP
Expand Down

0 comments on commit 5d93806

Please sign in to comment.