Despite the name, the Selenium RC (Remote Control) server is often run on the same machine as the testing framework, which makes saving screenshots to disk quite easy. If however you are running Selenium RC on a separate machine, or are using Selenium Grid it can become more difficult as the screenshots are also saved on the remote machines.
To solve this you can use the
captureEntirePageScreenshotToString commands, which return a Base64 encoded
String of the screenshot, which you can then decode and save to disk on your
The following demonstrates the latter command (entire screenshot) in Java. I
have added this to a TestNG
afterInvocation listener for failed tests so that
I have a screenshot of the page that resulted in the failure, which can be very
valuable for diagnosing issues.
- This example uses
- In this example,
outputDirectoryis set in a
onStartlistener from the
- In reality you’d want to construct
imageNamefrom the test method name so that it is unique for each test
captureEntireScreenshot*commands have limited browser support. Currently I only capture these screenshots if the browser is Firefox