Skip to content

Commit

Permalink
QE-11255 Use tenacity.retry in page checks (#324)
Browse files Browse the repository at this point in the history
cucu's retry function has hooks that are used to run other functions
during retry, e.g., disabling toast. Those functions shouldn't be run
during page check retry. This PR replaces cucu retry with tenacity.retry
in page checks to avoid those hooks.
  • Loading branch information
ddl-xin authored Apr 13, 2023
1 parent 49fc02c commit 75071cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion features/flow_control/before_retry_handlers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Feature: Before retry handlers
Scenario: Scenario with an before retry handler
Given I start a webserver at directory "data/www" and save the port to the variable "PORT" .*
.* INFO handled the pesky button buttons!
And I open a browser at the url "http://\{HOST_ADDRESS\}:\{PORT\}/links.html" .*
[\s\S]*
.* INFO handled the pesky button buttons!
Then I wait to see the button "button with child" .*
1 feature passed, 0 failed, 0 skipped
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cucu"
version = "0.125.0"
version = "0.126.0"
license = "MIT"
description = ""
authors = ["Rodney Gomes <[email protected]>"]
Expand Down
16 changes: 13 additions & 3 deletions src/cucu/page_checks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from cucu import config, retry, register_page_check_hook, logger
from tenacity import retry, stop_after_delay, wait_fixed

from cucu import config, logger, register_page_check_hook


def init_page_checks():
"""
initialize cucu built in page checks
"""

@retry(
stop=stop_after_delay(float(config.CONFIG["CUCU_STEP_WAIT_TIMEOUT_S"])),
wait=wait_fixed(float(config.CONFIG["CUCU_STEP_RETRY_AFTER_S"])),
)
def wait_for_document_to_be_ready(browser):
if config.CONFIG["CUCU_READY_STATE_PAGE_CHECK"] == "enabled":
state = browser.execute("return document.readyState;")
Expand All @@ -16,9 +22,13 @@ def wait_for_document_to_be_ready(browser):
logger.debug("document.readyState check disabled")

register_page_check_hook(
"wait for document.readyState", retry(wait_for_document_to_be_ready)
"wait for document.readyState", wait_for_document_to_be_ready
)

@retry(
stop=stop_after_delay(float(config.CONFIG["CUCU_STEP_WAIT_TIMEOUT_S"])),
wait=wait_fixed(float(config.CONFIG["CUCU_STEP_RETRY_AFTER_S"])),
)
def wait_for_all_images_to_be_loaded(browser):
if config.CONFIG["CUCU_BROKEN_IMAGES_PAGE_CHECK"] == "enabled":
broken_images = browser.execute(
Expand All @@ -45,5 +55,5 @@ def wait_for_all_images_to_be_loaded(browser):
logger.debug("broken image check disabled")

register_page_check_hook(
"broken image checker", retry(wait_for_all_images_to_be_loaded)
"broken image checker", wait_for_all_images_to_be_loaded
)

0 comments on commit 75071cd

Please sign in to comment.