{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
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 ScreenCaptureProcessors are capable of processing the ScreenCapture that was created.
This API is currently in beta.
Nested types |
|
|---|---|
Screenshot.ScreenShotException |
An Exception associated with failing to capture a screenshot. |
Public constructors |
|
|---|---|
Public methods |
|
|---|---|
static @NonNull void |
addScreenCaptureProcessors(Adds the given set of |
static @NonNull ScreenCapture |
capture()Creates a |
static @NonNull ScreenCapture |
Creates a |
static @NonNull ScreenCapture |
Creates a |
static @NonNull void |
setScreenshotProcessors(Sets the current set of |
@NonNull
public static void addScreenCaptureProcessors(
@NonNull Set<@NonNull ScreenCaptureProcessor> screenCaptureProcessors
)
Adds the given set of ScreenCaptureProcessors to the current set of ScreenCaptureProcessors.
The current set of ScreenCaptureProcessors will be passed to each ScreenCapture that is created.
| Parameters | |
|---|---|
@NonNull Set<@NonNull ScreenCaptureProcessor> screenCaptureProcessors |
the set of |
@NonNull
public static ScreenCapture capture()
Creates a ScreenCapture that contains a Bitmap of the visible screen content for Build.VERSION_CODES.JELLY_BEAN_MR2 and above.
The ScreenCapture that is returned will also contain the set of ScreenCaptureProcessors that have been set in this instance.
Note: Only use this method if all your tests run on API versions Build.VERSION_CODES.JELLY_BEAN_MR2 or above. If you need to take screenshots on lower API levels, you need to use capture or capture for those versions.
| Returns | |
|---|---|
ScreenCapture |
a |
| 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 |
@NonNull
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 ScreenCaptureProcessors that have been set in this instance.
| Parameters | |
|---|---|
@NonNull Activity activity |
the Activity who's root View will be used to create a Bitmap |
| Returns | |
|---|---|
ScreenCapture |
a |
| Throws | |
|---|---|
java.lang.NullPointerException |
if given activity is null |
androidx.test.runner.screenshot.Screenshot.ScreenShotException |
If there was an error capturing the screenshot |
@NonNull
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 ScreenCaptureProcessors that have been set in this instance.
| Parameters | |
|---|---|
@NonNull View view |
the View to create a Bitmap of |
| Returns | |
|---|---|
ScreenCapture |
|
| Throws | |
|---|---|
java.lang.NullPointerException |
if given view is null |
androidx.test.runner.screenshot.Screenshot.ScreenShotException |
If there was an error capturing the screenshot |
@NonNull
public static void setScreenshotProcessors(
@NonNull Set<@NonNull ScreenCaptureProcessor> screenCaptureProcessors
)
Sets the current set of ScreenCaptureProcessors to the given set of ScreenCaptureProcessors.
The current set of ScreenCaptureProcessors will be passed to each ScreenCapture that is created.
| Parameters | |
|---|---|
@NonNull Set<@NonNull ScreenCaptureProcessor> screenCaptureProcessors |
the set of |