fitzee commented on code in PR #44034:
URL: https://github.com/apache/superset/pull/44034#discussion_r3963884474
##########
superset/utils/webdriver.py:
##########
@@ -240,6 +243,105 @@ def _get_screenshot(
else:
return element.screenshot(**timeout_kwargs)
+ @staticmethod
+ def _get_validated_screenshot(
+ page: Page,
+ element: Locator,
+ element_name: str,
+ log_context: str | None,
+ report_execution_context: ReportExecutionContext | None,
+ ) -> bytes:
+ """Capture a standard screenshot and reject blank report output."""
+
+ context_suffix = f" [{log_context}]" if log_context else ""
+ content_expected = element_name == "chart-container" or bool(
+ report_execution_context and
report_execution_context.expected_chart_count
+ )
+ for attempt in range(1, TILED_SCREENSHOT_MAX_CAPTURE_ATTEMPTS + 1):
+ capture_timeout = (
+ report_execution_context.deadline.timeout_seconds(
+ "screenshot_capture",
+ reserve_seconds=(
+ report_execution_context.post_capture_reserve_seconds
+ ),
+ )
+ if report_execution_context
+ else None
+ )
+ capture_started_at = time.monotonic()
+ image = WebDriverPlaywright._get_screenshot(
+ page,
+ element,
+ element_name,
+ timeout_seconds=capture_timeout,
+ )
+ capture_elapsed = time.monotonic() - capture_started_at
+ if report_execution_context is None:
+ return image
+
+ blankness = get_screenshot_blankness_metrics(image)
+ is_blank = content_expected and blankness.is_blank
+ logger.info(
+ "report_capture_validation capture=standard attempt=%s/%s "
+ "capture_elapsed_seconds=%.2f is_blank=%s "
+ "dominant_pixel_ratio=%.5f near_white_pixel_ratio=%.5f "
+ "mean_luminance=%.2f luminance_stddev=%.2f entropy=%.3f%s",
+ attempt,
+ TILED_SCREENSHOT_MAX_CAPTURE_ATTEMPTS,
+ capture_elapsed,
+ is_blank,
+ blankness.dominant_pixel_ratio,
+ blankness.near_white_pixel_ratio,
+ blankness.mean_luminance,
+ blankness.luminance_stddev,
+ blankness.entropy,
+ context_suffix,
+ )
+ if not is_blank:
+ return image
+
+ logger.warning(
+ "report_capture_blank_standard attempt=%s/%s "
+ "capture_elapsed_seconds=%.2f dominant_pixel_ratio=%.5f "
+ "near_white_pixel_ratio=%.5f mean_luminance=%.2f "
+ "luminance_stddev=%.2f entropy=%.3f%s",
+ attempt,
+ TILED_SCREENSHOT_MAX_CAPTURE_ATTEMPTS,
+ capture_elapsed,
+ blankness.dominant_pixel_ratio,
+ blankness.near_white_pixel_ratio,
+ blankness.mean_luminance,
+ blankness.luminance_stddev,
+ blankness.entropy,
+ context_suffix,
+ )
+ if attempt == TILED_SCREENSHOT_MAX_CAPTURE_ATTEMPTS:
+ raise ScreenshotBlankCaptureError(
+ "Chromium returned a blank standard screenshot "
+ f"after {attempt} attempts"
+ )
+ try:
+ page.bring_to_front()
+ page.evaluate(
+ """() => {
+ window.scrollBy(0, 1);
+ window.scrollBy(0, -1);
+ return new Promise(resolve => requestAnimationFrame(
+ () => requestAnimationFrame(resolve)
+ ));
+ }"""
+ )
Review Comment:
Addressed in 6a9011bbbf. The standard repaint no longer returns a Promise
from page.evaluate(). It schedules a completion flag and waits with
page.wait_for_function() using a five-second timeout capped by the remaining
report deadline and post-capture reserve. Playwright repaint failures are
logged, while report-budget and Celery soft-time-limit exceptions propagate.
Added bounded-timeout and SoftTimeLimitExceeded regression tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]