@@ -64,7 +64,15 @@ 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_full_page_screenshot (self , filename : str = DEFAULT_FILENAME_PAGE ) -> str :
68
+ """Takes a full page screenshot of the current page and embeds it into a log file.
69
+
70
+ See the `Capture Page Screenshot` section for details.
71
+ """
72
+ return self .capture_page_screenshot (filename , full_screen = True )
73
+
74
+ @keyword
75
+ def capture_page_screenshot (self , filename : str = DEFAULT_FILENAME_PAGE , full_screen : bool = False ) -> str :
68
76
"""Takes a screenshot of the current page and embeds it into a log file.
69
77
70
78
``filename`` argument specifies the name of the file to write the
@@ -78,6 +86,8 @@ def capture_page_screenshot(self, filename: str = DEFAULT_FILENAME_PAGE) -> str:
78
86
is embedded as Base64 image to the log.html. In this case file is not
79
87
created in the filesystem.
80
88
89
+ If ``full_screen`` is True, then a full page screenshot will be taken.
90
+
81
91
Starting from SeleniumLibrary 1.8, if ``filename`` contains marker
82
92
``{index}``, it will be automatically replaced with an unique running
83
93
index, preventing files to be overwritten. Indices start from 1,
@@ -90,38 +100,49 @@ def capture_page_screenshot(self, filename: str = DEFAULT_FILENAME_PAGE) -> str:
90
100
91
101
Support for EMBED is new in SeleniumLibrary 4.2
92
102
103
+ Support for full_screen is new in SeleniumLibrary 5.x.x
104
+
93
105
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 |
106
+ | `Capture Page Screenshot` | | |
107
+ | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-1.png | |
108
+ | ${path} = | `Capture Page Screenshot` | |
109
+ | `File Should Exist` | ${OUTPUTDIR}/selenium-screenshot-2.png | |
110
+ | `File Should Exist` | ${path} | |
111
+ | `Capture Page Screenshot` | custom_name.png | |
112
+ | `File Should Exist` | ${OUTPUTDIR}/custom_name.png | |
113
+ | `Capture Page Screenshot` | custom_with_index_{index}.png | |
114
+ | `File Should Exist` | ${OUTPUTDIR}/custom_with_index_1.png | |
115
+ | `Capture Page Screenshot` | formatted_index_{index:03}.png | |
116
+ | `File Should Exist` | ${OUTPUTDIR}/formatted_index_001.png | |
117
+ | `Capture Page Screenshot` | EMBED | |
118
+ | `File Should Not Exist` | EMBED | |
119
+ | `Capture Full Page Screenshot` | EMBED | full_screen = True |
120
+ | `File Should Not Exist` | EMBED | |
107
121
"""
108
122
if not self .drivers .current :
109
123
self .info ("Cannot capture screenshot because no browser is open." )
110
124
return
111
125
if self ._decide_embedded (filename ):
112
- return self ._capture_page_screen_to_log ()
113
- return self ._capture_page_screenshot_to_file (filename )
126
+ return self ._capture_page_screen_to_log (full_screen )
127
+ return self ._capture_page_screenshot_to_file (filename , full_screen )
114
128
115
- def _capture_page_screenshot_to_file (self , filename ):
129
+ def _capture_page_screenshot_to_file (self , filename , full_screen = False ):
116
130
path = self ._get_screenshot_path (filename )
117
131
self ._create_directory (path )
118
- if not self .driver .save_screenshot (path ):
119
- raise RuntimeError (f"Failed to save screenshot '{ path } '." )
132
+ if full_screen :
133
+ if not self .driver .save_full_page_screenshot (path ):
134
+ raise RuntimeError (f"Failed to save full page screenshot '{ path } '." )
135
+ else :
136
+ if not self .driver .save_screenshot (path ):
137
+ raise RuntimeError (f"Failed to save screenshot '{ path } '." )
120
138
self ._embed_to_log_as_file (path , 800 )
121
139
return path
122
140
123
- def _capture_page_screen_to_log (self ):
124
- screenshot_as_base64 = self .driver .get_screenshot_as_base64 ()
141
+ def _capture_page_screen_to_log (self , full_screen = False ):
142
+ if full_screen :
143
+ screenshot_as_base64 = self .driver .get_full_page_screenshot_as_base64 ()
144
+ else :
145
+ screenshot_as_base64 = self .driver .get_screenshot_as_base64 ()
125
146
self ._embed_to_log_as_base64 (screenshot_as_base64 , 800 )
126
147
return EMBED
127
148
0 commit comments