espresso-test-lib/EspressoInstrumentation/src/com/tomtom/espresso/test/CucumberHelperTestSteps.java
public static void takeScreenshot(final String tag) {
        if (scenario == null) {
            throw new ScreenshotException("Error taking screenshot: I'm missing a valid test scenario to attach the screenshot to");
        }
        SpoonScreenshotAction.perform(tag);
        final File screenshot = SpoonScreenshotAction.getLastScreenshot();
        if (screenshot == null) {
            throw new ScreenshotException("Screenshot was not taken correctly, check for failures in screenshot library");
        }
        FileInputStream screenshotStream = null;
        try {
            screenshotStream = new FileInputStream(screenshot);
            final byte fileContent[] = new byte[(int)screenshot.length()];
            screenshotStream.read(fileContent); // Read data from input image file into an array of bytes
            scenario.embed(fileContent, "image/png"); // Embed the screenshot in the report under current test step
        }
        catch (final IOException ioe) {
            throw new ScreenshotException("Exception while reading file " + ioe);
        }
        finally {
            try { // close the streams using close method
                if (screenshotStream != null) {
                    screenshotStream.close();
                }
            }
            catch (final IOException ioe) {
                throw new ScreenshotException("Error while closing stream: " + ioe);
            }
        }
    }
/**
     * Take a screenshot of the current activity and embed it in the HTML report
     * @param tag Name of the screenshot to include in the file name
     */
Take a screenshot of the current activity and embed it in the HTML report
@param tag Name of the screenshot to include in the file name
Take a screenshot of the current activity and embed it in the HTML report @param tag Name of the screenshot to include in the file name
public static void takeScreenshot(final String tag) {
        if (scenario == null) {
            throw new ScreenshotException("Error taking screenshot: I'm missing a valid test scenario to attach the screenshot to");
        }
        SpoonScreenshotAction.perform(tag);
        final File screenshot = SpoonScreenshotAction.getLastScreenshot();
        if (screenshot == null) {
            throw new ScreenshotException("Screenshot was not taken correctly, check for failures in screenshot library");
        }
        FileInputStream screenshotStream = null;
        try {
            screenshotStream = new FileInputStream(screenshot);
            final byte fileContent[] = new byte[(int)screenshot.length()];
            screenshotStream.read(fileContent); 
            scenario.embed(fileContent, "image/png"); 
        }
        catch (final IOException ioe) {
            throw new ScreenshotException("Exception while reading file " + ioe);
        }
        finally {
            try { 
                if (screenshotStream != null) {
                    screenshotStream.close();
                }
            }
            catch (final IOException ioe) {
                throw new ScreenshotException("Error while closing stream: " + ioe);
            }
        }
    }
public static void takeScreenshot ( final String tag ) { if ( scenario == null ) { throw new ScreenshotException ( "Error taking screenshot: I'm missing a valid test scenario to attach the screenshot to" ) ; } SpoonScreenshotAction . perform ( tag ) ; final File screenshot = SpoonScreenshotAction . getLastScreenshot ( ) ; if ( screenshot == null ) { throw new ScreenshotException ( "Screenshot was not taken correctly, check for failures in screenshot library" ) ; } FileInputStream screenshotStream = null ; try { screenshotStream = new FileInputStream ( screenshot ) ; final byte fileContent [ ] = new byte [ ( int ) screenshot . length ( ) ] ; screenshotStream . read ( fileContent ) ; scenario . embed ( fileContent , "image/png" ) ; } catch ( final IOException ioe ) { throw new ScreenshotException ( "Exception while reading file " + ioe ) ; } finally { try { if ( screenshotStream != null ) { screenshotStream . close ( ) ; } } catch ( final IOException ioe ) { throw new ScreenshotException ( "Error while closing stream: " + ioe ) ; } } }
Take a screenshot of the current activity and embed it in the HTML report
 @param tag Name of the screenshot to include in the file name
Take a screenshot of the current activity and embed it in the HTML report @param tag Name of the screenshot to include in the file name
// Read data from input image file into an array of bytes // Embed the screenshot in the report under current test step // close the streams using close method