Screenshot


public final class Screenshot


The Screenshot instance provides methods to capture a ScreenCapture during instrumentation tests run on an android device.

The Screenshot instance keeps track of a set of ScreenCaptureProcessors that will be passed to each ScreenCapture object when they are created during any test. These s are capable of processing the ScreenCapture that was created.

Summary

Nested types

This class is deprecated.

use androidx.test.espresso.screenshot.captureToBitmap or androidx.test.core.app.DeviceCapture instead

Public constructors

Public methods

static void
addScreenCaptureProcessors(
    Set<ScreenCaptureProcessor> screenCaptureProcessors
)

Adds the given set of ScreenCaptureProcessors to the current set of s.

static ScreenCapture

Creates a ScreenCapture that contains a Bitmap of the visible screen content.

static ScreenCapture

Creates a ScreenCapture that contains a Bitmap of the given activity's root View hierarchy content.

static ScreenCapture

Creates a ScreenCapture that contains a Bitmap of the given view's hierarchy content.

static void
setScreenshotProcessors(
    Set<ScreenCaptureProcessor> screenCaptureProcessors
)

Sets the current set of ScreenCaptureProcessors to the given set of s.

Public constructors

Screenshot

public Screenshot()

Public methods

addScreenCaptureProcessors

public static void addScreenCaptureProcessors(
    Set<ScreenCaptureProcessor> screenCaptureProcessors
)

Adds the given set of ScreenCaptureProcessors to the current set of s.

The current set of ScreenCaptureProcessors will be passed to each that is created.

Parameters
Set<ScreenCaptureProcessor> screenCaptureProcessors

the set of ScreenCaptureProcessors to add

capture

public static ScreenCapture capture()

Creates a ScreenCapture that contains a Bitmap of the visible screen content.

The ScreenCapture that is returned will also contain the set of s that have been set in this instance.

Returns
ScreenCapture

a ScreenCapture that contains the bitmap of the visible screen content.

Throws
java.lang.IllegalStateException

if used on API below Build.VERSION_CODES.JELLY_BEAN_MR2

androidx.test.runner.screenshot.Screenshot.ScreenShotException

If there was an error capturing the screenshot

capture

public static ScreenCapture capture(@NonNull Activity activity)

Creates a ScreenCapture that contains a Bitmap of the given activity's root View hierarchy content.

The ScreenCapture that is returned will also contain the set of s that have been set in this instance.

Parameters
@NonNull Activity activity

the Activity who's root View will be used to create a

Returns
ScreenCapture

a ScreenCapture that contains the bitmap of the given activity's root .

Throws
java.lang.NullPointerException

if given activity is null

androidx.test.runner.screenshot.Screenshot.ScreenShotException

If there was an error capturing the screenshot

capture

public static ScreenCapture capture(@NonNull View view)

Creates a ScreenCapture that contains a Bitmap of the given view's hierarchy content.

The ScreenCapture that is returned will also contain the set of s that have been set in this instance.

Parameters
@NonNull View view

the View to create a Bitmap of

Returns
ScreenCapture

ScreenCapture that contains the bitmap of the given view's hierarchy content.

Throws
java.lang.NullPointerException

if given view is null

androidx.test.runner.screenshot.Screenshot.ScreenShotException

If there was an error capturing the screenshot

setScreenshotProcessors

public static void setScreenshotProcessors(
    Set<ScreenCaptureProcessor> screenCaptureProcessors
)

Sets the current set of ScreenCaptureProcessors to the given set of s.

The current set of ScreenCaptureProcessors will be passed to each that is created.

Parameters
Set<ScreenCaptureProcessor> screenCaptureProcessors

the set of ScreenCaptureProcessors to use