Skip to content

Commit

Permalink
chore: Add config options for Playwright wait_until and default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Oct 26, 2023
1 parent c7f8d11 commit 28df3a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,11 @@ class D3Format(TypedDict, total=False):
SCREENSHOT_WAIT_FOR_ERROR_MODAL_VISIBLE = 5
# Max time to wait for error message modal to close, in seconds
SCREENSHOT_WAIT_FOR_ERROR_MODAL_INVISIBLE = 5
# event that Playwright waits for when loading a new page
# possible values: "load", "commit", "domcontentloaded", "networkidle"
SCREENSHOT_PLAYWRIGHT_WAIT_UNTIL = "load"
# default timeout for Playwright browser context for all operations
SCREENSHOT_PLAYWRIGHT_DEFAULT_TIMEOUT = 10000

# ---------------------------------------------------
# Image and file configuration
Expand Down
22 changes: 11 additions & 11 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from playwright.sync_api import (
BrowserContext,
ElementHandle,
Error,
Error as PlaywrightError,
Page,
sync_playwright,
TimeoutError as PlaywrightTimeout,
Expand Down Expand Up @@ -140,9 +140,9 @@ def find_unexpected_errors(page: Page) -> list[str]:
"(node, error_html) => node.innerHtml = error_html",
[error_as_html],
)
except Error:
except PlaywrightError:
logger.exception("Failed to update error messages using alert_div")
except Error:
except PlaywrightError:
logger.exception("Failed to capture unexpected errors")

return error_messages
Expand All @@ -161,9 +161,14 @@ def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | Non
},
device_scale_factor=pixel_density,
)
context.set_default_timeout(
current_app.config["SCREENSHOT_PLAYWRIGHT_DEFAULT_TIMEOUT"]
)
self.auth(user, context)
page = context.new_page()
page.goto(url)
page.goto(
url, wait_until=current_app.config["SCREENSHOT_PLAYWRIGHT_WAIT_UNTIL"]
)
img: bytes | None = None
selenium_headstart = current_app.config["SCREENSHOT_SELENIUM_HEADSTART"]
logger.debug("Sleeping for %i seconds", selenium_headstart)
Expand Down Expand Up @@ -236,14 +241,9 @@ def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | Non
except PlaywrightTimeout:
# raise again for the finally block, but handled above
pass
except StaleElementReferenceException:
logger.exception(
"Selenium got a stale element while requesting url %s",
url,
)
except WebDriverException:
except PlaywrightError:
logger.exception(
"Encountered an unexpected error when requeating url %s", url
"Encountered an unexpected error when requesting url %s", url
)
return img

Expand Down

0 comments on commit 28df3a8

Please sign in to comment.