@@ -64,7 +64,7 @@ def set_screenshot_directory(self, path: Union[None, str]) -> str:
64
64
return previous
65
65
66
66
@keyword
67
- def capture_page_screenshot (self , filename : str = DEFAULT_FILENAME_PAGE ) -> str :
67
+ def capture_page_screenshot (self , filename : str = DEFAULT_FILENAME_PAGE , full_screen : bool = False ) -> str :
68
68
"""Takes a screenshot of the current page and embeds it into a log file.
69
69
70
70
``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:
78
78
is embedded as Base64 image to the log.html. In this case file is not
79
79
created in the filesystem.
80
80
81
+ If ``full_screen`` is True, then a full page screenshot will be taken.
82
+ Only firefox driver support this. On other drivers, this option has
83
+ no effect.
84
+
81
85
Starting from SeleniumLibrary 1.8, if ``filename`` contains marker
82
86
``{index}``, it will be automatically replaced with an unique running
83
87
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:
90
94
91
95
Support for EMBED is new in SeleniumLibrary 4.2
92
96
97
+ Support for full_screen is new in SeleniumLibrary 5.2.0
98
+
93
99
Examples:
94
- | `Capture Page Screenshot` | |
95
- | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-1.png |
96
- | ${path} = | `Capture Page Screenshot` |
97
- | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-2.png |
98
- | `File Should Exist` | ${path} |
99
- | `Capture Page Screenshot` | custom_name.png |
100
- | `File Should Exist` | ${OUTPUTDIR}/custom_name.png |
101
- | `Capture Page Screenshot` | custom_with_index_{index}.png |
102
- | `File Should Exist` | ${OUTPUTDIR}/custom_with_index_1.png |
103
- | `Capture Page Screenshot` | formatted_index_{index:03}.png |
104
- | `File Should Exist` | ${OUTPUTDIR}/formatted_index_001.png |
105
- | `Capture Page Screenshot` | EMBED |
106
- | `File Should Not Exist` | EMBED |
100
+ | `Capture Page Screenshot` | | |
101
+ | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-1.png | |
102
+ | ${path} = | `Capture Page Screenshot` | |
103
+ | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-2.png | |
104
+ | `File Should Exist` | ${path} | |
105
+ | `Capture Page Screenshot` | custom_name.png | |
106
+ | `File Should Exist` | ${OUTPUTDIR}/custom_name.png | |
107
+ | `Capture Page Screenshot` | custom_with_index_{index}.png | |
108
+ | `File Should Exist` | ${OUTPUTDIR}/custom_with_index_1.png | |
109
+ | `Capture Page Screenshot` | formatted_index_{index:03}.png | |
110
+ | `File Should Exist` | ${OUTPUTDIR}/formatted_index_001.png | |
111
+ | `Capture Page Screenshot` | EMBED | |
112
+ | `File Should Not Exist` | EMBED | |
113
+ | `Capture Full Page Screenshot` | EMBED | full_screen = True |
114
+ | `File Should Not Exist` | EMBED | |
107
115
"""
108
116
if not self .drivers .current :
109
117
self .info ("Cannot capture screenshot because no browser is open." )
110
118
return
111
119
if self ._decide_embedded (filename ):
112
- return self ._capture_page_screen_to_log ()
113
- return self ._capture_page_screenshot_to_file (filename )
120
+ return self ._capture_page_screen_to_log (full_screen )
121
+ return self ._capture_page_screenshot_to_file (filename , full_screen )
114
122
115
- def _capture_page_screenshot_to_file (self , filename ):
123
+ def _capture_page_screenshot_to_file (self , filename , full_screen = False ):
116
124
path = self ._get_screenshot_path (filename )
117
125
self ._create_directory (path )
118
- if not self .driver .save_screenshot (path ):
119
- raise RuntimeError (f"Failed to save screenshot '{ path } '." )
126
+ if full_screen and hasattr (self .driver , 'save_full_page_screenshot' ):
127
+ if not self .driver .save_full_page_screenshot (path ):
128
+ raise RuntimeError (f"Failed to save full page screenshot '{ path } '." )
129
+ else :
130
+ if not self .driver .save_screenshot (path ):
131
+ raise RuntimeError (f"Failed to save screenshot '{ path } '." )
120
132
self ._embed_to_log_as_file (path , 800 )
121
133
return path
122
134
123
- def _capture_page_screen_to_log (self ):
124
- screenshot_as_base64 = self .driver .get_screenshot_as_base64 ()
135
+ def _capture_page_screen_to_log (self , full_screen = False ):
136
+ if full_screen and hasattr (self .driver , 'get_full_page_screenshot_as_base64' ):
137
+ screenshot_as_base64 = self .driver .get_full_page_screenshot_as_base64 ()
138
+ else :
139
+ screenshot_as_base64 = self .driver .get_screenshot_as_base64 ()
125
140
self ._embed_to_log_as_base64 (screenshot_as_base64 , 800 )
126
141
return EMBED
127
142
0 commit comments