From 4354b6088957b5932afaecc9daa77836c22cded6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Fri, 29 Sep 2023 17:04:13 +0200 Subject: [PATCH] Be able to add an additional timeout to wait that the page is fully loaded --- c2cwsgiutils/acceptance/image.py | 2 ++ c2cwsgiutils/acceptance/screenshot.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/c2cwsgiutils/acceptance/image.py b/c2cwsgiutils/acceptance/image.py index e531745b8..f5a53b7e1 100644 --- a/c2cwsgiutils/acceptance/image.py +++ b/c2cwsgiutils/acceptance/image.py @@ -159,6 +159,7 @@ def check_screenshot( expected_filename: str, width: int = 800, height: int = 600, + sleep: int = 0, headers: Optional[dict[str, str]] = None, media: Optional[list[dict[str, str]]] = None, level: float = 1.0, @@ -192,6 +193,7 @@ def check_screenshot( f"--url={url}", f"--width={width}", f"--height={height}", + f"--sleep={sleep}", f"--headers={json.dumps(headers)}", f"--media={json.dumps(media)}", f"--output={actual_filename}", diff --git a/c2cwsgiutils/acceptance/screenshot.js b/c2cwsgiutils/acceptance/screenshot.js index 99c017fa4..9661df891 100644 --- a/c2cwsgiutils/acceptance/screenshot.js +++ b/c2cwsgiutils/acceptance/screenshot.js @@ -6,6 +6,7 @@ program .option('--output ', 'The output filename') .option('--width ', 'The page width', 800) .option('--height ', 'The page height', 600) + .option('--sleep ', 'Sleep that the page is fully loaded [ms]', 0) .option('--headers ', 'The headers', '{}') // see: https://pptr.dev/api/puppeteer.page.emulatemediafeatures .option('--media ', 'The media feature, see Page.emulateMediaFeatures', '[]'); @@ -54,6 +55,7 @@ const options = program.opts(); width: parseInt(options.width), height: parseInt(options.height), }); + await page.waitForTimeout(parseInt(options.sleep)); await page.screenshot({ path: options.output, clip: { x: 0, y: 0, width: parseInt(options.width), height: parseInt(options.height) },