From d091adbe31326db7589d877bbc403517ef198501 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Sun, 12 Dec 2021 21:57:37 +0100 Subject: [PATCH 1/2] chore: Fix typo in CONTRIBUTING.rst --- CONTRIBUTING.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index de1a76316..b5ed4110a 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -159,7 +159,7 @@ Tests When submitting a pull request with a new feature or a fix, you should always include tests for your changes. These tests prove that your changes work, help prevent bugs in the future, and help document what -your changes do. Depending an the change, you may need +your changes do. Depending on the change, you may need ``acceptance tests``\ *, ``unit tests``* or both. Make sure to run all of the tests before submitting a pull request to be From a3e318664ce1aabe1c549d21b95ff6b80c1b87a5 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Sun, 12 Dec 2021 21:54:29 +0100 Subject: [PATCH 2/2] feat: Allow full_screen screenshots on Firefox Fix #1459 --- src/SeleniumLibrary/keywords/screenshot.py | 57 ++++++++++++++-------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/SeleniumLibrary/keywords/screenshot.py b/src/SeleniumLibrary/keywords/screenshot.py index 628361c8a..c4e815fd0 100644 --- a/src/SeleniumLibrary/keywords/screenshot.py +++ b/src/SeleniumLibrary/keywords/screenshot.py @@ -64,7 +64,7 @@ def set_screenshot_directory(self, path: Union[None, str]) -> str: return previous @keyword - def capture_page_screenshot(self, filename: str = DEFAULT_FILENAME_PAGE) -> str: + def capture_page_screenshot(self, filename: str = DEFAULT_FILENAME_PAGE, full_screen: bool = False) -> str: """Takes a screenshot of the current page and embeds it into a log file. ``filename`` argument specifies the name of the file to write the @@ -78,6 +78,10 @@ def capture_page_screenshot(self, filename: str = DEFAULT_FILENAME_PAGE) -> str: is embedded as Base64 image to the log.html. In this case file is not created in the filesystem. + If ``full_screen`` is True, then a full page screenshot will be taken. + Only firefox driver support this. On other drivers, this option has + no effect. + Starting from SeleniumLibrary 1.8, if ``filename`` contains marker ``{index}``, it will be automatically replaced with an unique running index, preventing files to be overwritten. Indices start from 1, @@ -90,38 +94,49 @@ def capture_page_screenshot(self, filename: str = DEFAULT_FILENAME_PAGE) -> str: Support for EMBED is new in SeleniumLibrary 4.2 + Support for full_screen is new in SeleniumLibrary 5.2.0 + Examples: - | `Capture Page Screenshot` | | - | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-1.png | - | ${path} = | `Capture Page Screenshot` | - | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-2.png | - | `File Should Exist` | ${path} | - | `Capture Page Screenshot` | custom_name.png | - | `File Should Exist` | ${OUTPUTDIR}/custom_name.png | - | `Capture Page Screenshot` | custom_with_index_{index}.png | - | `File Should Exist` | ${OUTPUTDIR}/custom_with_index_1.png | - | `Capture Page Screenshot` | formatted_index_{index:03}.png | - | `File Should Exist` | ${OUTPUTDIR}/formatted_index_001.png | - | `Capture Page Screenshot` | EMBED | - | `File Should Not Exist` | EMBED | + | `Capture Page Screenshot` | | | + | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-1.png | | + | ${path} = | `Capture Page Screenshot` | | + | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-2.png | | + | `File Should Exist` | ${path} | | + | `Capture Page Screenshot` | custom_name.png | | + | `File Should Exist` | ${OUTPUTDIR}/custom_name.png | | + | `Capture Page Screenshot` | custom_with_index_{index}.png | | + | `File Should Exist` | ${OUTPUTDIR}/custom_with_index_1.png | | + | `Capture Page Screenshot` | formatted_index_{index:03}.png | | + | `File Should Exist` | ${OUTPUTDIR}/formatted_index_001.png | | + | `Capture Page Screenshot` | EMBED | | + | `File Should Not Exist` | EMBED | | + | `Capture Full Page Screenshot` | EMBED | full_screen = True | + | `File Should Not Exist` | EMBED | | """ if not self.drivers.current: self.info("Cannot capture screenshot because no browser is open.") return if self._decide_embedded(filename): - return self._capture_page_screen_to_log() - return self._capture_page_screenshot_to_file(filename) + return self._capture_page_screen_to_log(full_screen) + return self._capture_page_screenshot_to_file(filename, full_screen) - def _capture_page_screenshot_to_file(self, filename): + def _capture_page_screenshot_to_file(self, filename, full_screen = False): path = self._get_screenshot_path(filename) self._create_directory(path) - if not self.driver.save_screenshot(path): - raise RuntimeError(f"Failed to save screenshot '{path}'.") + if full_screen and hasattr(self.driver, 'save_full_page_screenshot'): + if not self.driver.save_full_page_screenshot(path): + raise RuntimeError(f"Failed to save full page screenshot '{path}'.") + else: + if not self.driver.save_screenshot(path): + raise RuntimeError(f"Failed to save screenshot '{path}'.") self._embed_to_log_as_file(path, 800) return path - def _capture_page_screen_to_log(self): - screenshot_as_base64 = self.driver.get_screenshot_as_base64() + def _capture_page_screen_to_log(self, full_screen = False): + if full_screen and hasattr(self.driver, 'get_full_page_screenshot_as_base64'): + screenshot_as_base64 = self.driver.get_full_page_screenshot_as_base64() + else: + screenshot_as_base64 = self.driver.get_screenshot_as_base64() self._embed_to_log_as_base64(screenshot_as_base64, 800) return EMBED