Delivered by FeedBurner

Appium - Capture Screenshot Android App Mobile Screen

Capturing screenshot in appium android automation Is main requirement for any software automation tool. During software automation testing process, It should allow you to capture screenshot automatically to show bug or some design Issue to development/design team. For android software application automation testing using appium, We can use TakesScreenshot Interface of WebDriver to capture screenshot of android app screen. I have prepared simple example on how to capture screenshot In android appium automation software test using TakesScreenshot Interface of WebDriver.

App To Use Capture Screenshot Test
We will use API Demos android software app for Capture Screenshot test. You can download it from HERE.

Aim to Achieve In Capture Screenshot Test
We wants to capture screenshot of android mobile screen on some stage of appium automation test. And then we will store It Inside screenshots folder under project. We will prepare file name using current date time programmatically as shown In bellow Image.

Above Image shows screenshot which Is taken during android appium automation test.

Create And Run Capture Screenshot Test
Create new file file under your Android package of your project and write bellow given test script In It.

package Android;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CaptureScreenShot {
 AndroidDriver driver;
 Dimension size;
 String destDir;
 DateFormat dateFormat;

 public void setUp() throws Exception {
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", "ZX1B32FFXF");
  capabilities.setCapability("browserName", "Android");
  capabilities.setCapability("platformVersion", "4.4.2");
  capabilities.setCapability("platformName", "Android");
  capabilities.setCapability("appPackage", "");
  capabilities.setCapability("appActivity", "");
  driver = new AndroidDriver(new URL(""), capabilities);
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

 public void ScrollToTab() {
  // Scroll till element which contains "Views" text If It Is not visible on screen.
  // Click on Views.
  // Scroll till element which contains "Tabs" text If It Is not visible on screen.
  //Call takeScreenShot() function to capture screenshot of android screen.


 public void takeScreenShot() {
  // Set folder name to store screenshots.
  destDir = "screenshots";
  // Capture screenshot.
  File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
  // Set date format to set It as screenshot file name.
  dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
  // Create folder under project with name "screenshots" provided to destDir.
  new File(destDir).mkdirs();
  // Set file name using current date time.
  String destFile = dateFormat.format(new Date()) + ".png";

  try {
   // Copy paste file at destination folder location
   FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
  } catch (IOException e) {

 public void End() {

Test Description
Above android appium software test will navigate to Views screen and scroll down till Tabs text on API Demos android app. Then It will call takeScreenShot(); method to capture and store android app screenshot. takeScreenShot() method will,
  • Capture screenshot using TakesScreenshot Interface of webdriver.
  • Get current date and time and store It in variable.
  • Create new folder with name "screenshots" under your project.
  • Set file name using current date and time.
  • Store file In "screenshots" folder.
When you run above test, It will create screenshots folder under your project and store screenshot file In It. Refresh your project folder after test execution to see new created folder and screenshot file.

This way you can capture and store screenshot of any android app.


  1. Hey, this actually helped me today. Cheers!

  2. Hey, this actually helped me today. Cheers!

  3. How can I now load this image into Bitmap? I've tried using BitmapFactory's decodeFile and decodeStream methods but it keeps returning null.