Currently Browsing

Posts Tagged ‘ Screenshot ’

Mobile testing -Taking Screenshot on Android

Taking a screenshot while testing on Android phone can be a bit confusing, since the process isn’t the same on every device. There are different ways to take a screenshot.

1 – Ice Cream Sandwich (4.0) and above

If you have Android Smartphone with Ice Cream Sandwich or above installed, screenshot option is built-in! Just press the Volume Down and Power buttons at the same time, hold them for a second, and your phone will take a screenshot.

Capturing screenshots of failed tests in Selenium Webdriver + JUnit4

Beside the exception / failure information, it is almost always helpful for the developers to provide them with additional screenshot of the failed tests.
From JUnit 4.7 the @Rule annotation is introduced which can be used to extend the capabilities of JUnit. With it we can invoke a custom piece of code when a test fails or succeeds.
In this example we will capture a screenshot of a failed test.
Before showing how it is done, we should have a test class at hand. For the following example just download the selenium driver from the page and add the jar files to classpath.

package test;

import static org.junit.Assert.assertTrue;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.thoughtworks.selenium.Selenium;

//This is an example for the usage of ScreenshotTestRule
public class TestWithScreenshotExample {
    static WebDriver driver;
    static Selenium selenium;
    // an annotation is used for defining a new rule for Junit
    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();

    public static void beforeClass() {
        driver = new FirefoxDriver();
        selenium = new WebDriverBackedSelenium(driver, "");

    public static void afterClass() {

    public void testThatSucceeds() {"/");
        // some text code here
        assertTrue(selenium.isTextPresent("This test will pass"));

    public void testThatFails() {"/");
        //some text code here
        assertTrue(selenium.isTextPresent("This test will fail"));

    // the static driver object will be needed for capturing screenshots
	public static WebDriver getDriver() {
		return driver;

The trick above is to define a new JUnit rule with @Rule annotation.
The class which is used to define the new rule needs to implement the MethodRule interface and to override the apply() function.

How To Make Android Screenshots for testing

When testing Android mobile applications the one of the first things that come up is how to record and document the error that happened.
As in desktop testing there are apps that allow you to record the screen. The only thing that you need to do is to make sure the phone
is rooted before using the screenshot applications. (there are several descriptions out there just Google for them for the specific android
version and phone model).

Here is a list of screenshot applications:

Screenshot V1.4 from (I Suggest this one)

  • You can use the camera button to take screenshots
  • You can also choose to shake the phone to take pictures when you want

Screenshot It Trial from (only 5 screenshots in the trial mode)

  • Hold down the camera button
  • Assign a hot key to the application
  • Use a delayed timer