Skip to content

Commit

Permalink
Closes #2330 #2337
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtlmoon committed May 14, 2024
1 parent ef910b8 commit a9e7002
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions changedetectionio/blueprint/browser_steps/browser_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
# ONLY Works in Playwright because we need the fullscreen screenshot
class steppable_browser_interface():
page = None
start_url = None

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

# Convert and perform "Click Button" for example
def call_action(self, action_name, selector=None, optional_value=None):
Expand Down Expand Up @@ -87,6 +91,10 @@ def action_goto_url(self, selector=None, value=None):
logger.debug(f"Time to goto URL {time.time()-now:.2f}s")
return response

# Incase they request to go back to the start
def action_goto_site(self, selector=None, value=None):
return self.action_goto_url(value=self.start_url)

def action_click_element_containing_text(self, selector=None, value=''):
if not len(value.strip()):
return
Expand Down
7 changes: 3 additions & 4 deletions changedetectionio/content_fetchers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,21 @@ def get_all_headers(self):
def browser_steps_get_valid_steps(self):
if self.browser_steps is not None and len(self.browser_steps):
valid_steps = filter(
lambda s: (s['operation'] and len(s['operation']) and s['operation'] != 'Choose one' and s['operation'] != 'Goto site'),
lambda s: (s['operation'] and len(s['operation']) and s['operation'] != 'Choose one'),
self.browser_steps)

return valid_steps

return None

def iterate_browser_steps(self):
def iterate_browser_steps(self, start_url=None):
from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface
from playwright._impl._errors import TimeoutError, Error
from changedetectionio.safe_jinja import render as jinja_render

step_n = 0

if self.browser_steps is not None and len(self.browser_steps):
interface = steppable_browser_interface()
interface = steppable_browser_interface(start_url=start_url)
interface.page = self.page
valid_steps = self.browser_steps_get_valid_steps()

Expand Down
4 changes: 2 additions & 2 deletions changedetectionio/content_fetchers/playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def run(self,

# Re-use as much code from browser steps as possible so its the same
from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface
browsersteps_interface = steppable_browser_interface()
browsersteps_interface = steppable_browser_interface(start_url=url)
browsersteps_interface.page = self.page

response = browsersteps_interface.action_goto_url(value=url)
Expand Down Expand Up @@ -172,7 +172,7 @@ def run(self,

# Run Browser Steps here
if self.browser_steps_get_valid_steps():
self.iterate_browser_steps()
self.iterate_browser_steps(start_url=url)

self.page.wait_for_timeout(extra_wait * 1000)

Expand Down

0 comments on commit a9e7002

Please sign in to comment.