Take screenshots
In cases where you would want to automatically take screenshots, be it to file a bug when an assert condition fails, or just to document how the app looks on different viewports, you can take screenshots from within the tests. You can save these screenshots to the machine (e.g. CI/CD build server) that runs your automated tests.
Here is an example of code snippet to take a screenshot and save it to your machine:
/* Import the relevant packages */
/* your test code */
/* Take a screenshot */
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
/* Save screenshot to /location/to/screenshot.png */
//Import the relevant packages
// your test code
// Take a screenshot
let screenshot = driver.takeScreenshot();
let screenshot = await driver.takeScreenshot();
// Save screenshot to /location/to/screenshot.png
//Import the relevant packages
// your test code
// Take a screenshot
Screenshot screenshot = driver.GetScreenshot();
// Save screenshot to /location/to/screenshot.png
//Import the relevant packages
// your test code
// Take a screenshot
file_put_contents('screenshot.png', $driver->takeScreenshot());
// Save screenshot to /location/to/screenshot.png
# Import the relevant packages
# your test code
# Take a screenshot
screenshotBase64 = self.driver.get_screenshot_as_base64()
# Save screenshot to /location/to/screenshot.png
# Import the relevant packages
# Your test code
# Take a screenshot
# ruby_lib example
driver.screenshot_as(:base64) # via core_lib
# Save screenshot to /location/to/screenshot.png
Check out how you can capture screenshots can be captured automatically using the debug
capability.
Note: Some platforms may have settings that prevent screenshots from being taken, for security reasons. One such feature is the Android FLAG_SECURE layout parameter.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!