@@ -2151,20 +2151,27 @@ sub _convert_to_webelement {
21512151
21522152 Description:
21532153 Get a screenshot of the current page as a base64 encoded image.
2154+ Optionally pass {'full' => 1} as argument to take a full screenshot and not
2155+ only the viewport. (Works only with firefox and geckodriver >= 0.24.0)
21542156
21552157 Output:
21562158 STRING - base64 encoded image
21572159
21582160 Usage:
21592161 print $driver->screenshot();
2162+ print $driver->screenshot({'full' => 1});
21602163
21612164To conveniently write the screenshot to a file, see L</capture_screenshot> .
21622165
21632166=cut
21642167
21652168sub screenshot {
2166- my ($self ) = @_ ;
2167- my $res = { ' command' => ' screenshot' };
2169+ my ($self , $params ) = @_ ;
2170+ $params //= { full => 0 };
2171+
2172+ croak " Full page screenshot only supported on geckodriver" if $params -> {full } && ( $self -> {browser } ne ' firefox' );
2173+
2174+ my $res = { ' command' => $params -> {' full' } == 1 ? ' mozScreenshotFull' : ' screenshot' };
21682175 return $self -> _execute_command($res );
21692176}
21702177
@@ -2173,22 +2180,25 @@ sub screenshot {
21732180 Description:
21742181 Capture a screenshot and save as a PNG to provided file name.
21752182 (The method is compatible with the WWW::Selenium method of the same name)
2183+ Optionally pass {'full' => 1} as second argument to take a full screenshot
2184+ and not only the viewport. (Works only with firefox and geckodriver >= 0.24.0)
21762185
21772186 Output:
21782187 TRUE - (Screenshot is written to file)
21792188
21802189 Usage:
21812190 $driver->capture_screenshot($filename);
2191+ $driver->capture_screenshot($filename, {'full' => 1});
21822192
21832193=cut
21842194
21852195sub capture_screenshot {
2186- my ( $self , $filename ) = @_ ;
2196+ my ( $self , $filename , $params ) = @_ ;
21872197 croak ' $filename is required' unless $filename ;
21882198
21892199 open ( my $fh , ' >' , $filename );
21902200 binmode $fh ;
2191- print $fh MIME::Base64::decode_base64( $self -> screenshot() );
2201+ print $fh MIME::Base64::decode_base64( $self -> screenshot($params ) );
21922202 CORE::close $fh ;
21932203 return 1;
21942204}
0 commit comments