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

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.