Take Screenshot in Appium with this Simple Code

Screenshots serves an important role of acting as an evidence of any tests performed. Therefore screenshot capture functionality is very useful in any automated testing activities. WebDriver provides TakeScreenshot interface to capture screenshot of a web page. We can leverage that same method to take screenshot in Appium tool as well. In this post, we will explore how we can capture screenshot of an Android app using Appium tool.

For our example, we will capture screenshot of a native Android app running on Android emulator. We hope you have already setup Appium to use with an Android app. The code that we will see in steps below is written in Java. OK, enough with the talks. Let’s delve deep into the actual implementation now.

  • We will be using Augmenter class of WebDriver for screenshot capture functionality (Therefore, please make sure you have imported org.openqa.selenium.remote.Augmenter class in your test). To take screenshot in Appium, you just have to use below code in your tests.
  • As you can derive, the code uses the same method as WebDriver to take screenshot in Appium but with an additional help of Augmenter class.
  • On running this code, you will find a Screenshot.jpg file in root folder of your WebDriver project. You can also specify directory of your choice as copyFile method’s parameter.

The example code we have shown above is tested on Android app. But as Appium has a flexibility to use same code for both iOS and Android apps, you should be able to use same code on iOS app as well.

We hope the above tip to capture screenshot in Appium tool is useful to you. Let us know if you run across any issue while getting this to work. We would love to have your feedback in comments.

  1. Praveen
    • Niko
      • Ravi
  2. Shankar
  3. Anurag Sinha

Leave a Reply

Your email address will not be published.