{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
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.
Nested types |
|
|---|---|
Screenshot.ScreenShotException |
This class is deprecated. use androidx.test.espresso.screenshot.captureToBitmap or androidx.test.core.app.DeviceCapture instead |
Public constructors |
|
|---|---|
Public functions |
|
|---|---|
java-static Unit |
addScreenCaptureProcessors(Adds the given set of |
java-static ScreenCapture! |
capture()Creates a |
java-static ScreenCapture! |
Creates a |
java-static ScreenCapture! |
Creates a |
java-static Unit |
setScreenshotProcessors(Sets the current set of |
java-static fun addScreenCaptureProcessors(
screenCaptureProcessors: (Mutable)Set<ScreenCaptureProcessor!>!
): Unit
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 | |
|---|---|
screenCaptureProcessors: (Mutable)Set<ScreenCaptureProcessor!>! |
the set of |
java-static fun capture(): ScreenCapture!
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 s 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: java.lang.IllegalStateException |
if used on API below Build.VERSION_CODES.JELLY_BEAN_MR2 |
androidx.test.runner.screenshot.Screenshot.ScreenShotException: androidx.test.runner.screenshot.Screenshot.ScreenShotException |
If there was an error capturing the screenshot |
java-static fun capture(activity: Activity): ScreenCapture!
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.
| Returns | |
|---|---|
ScreenCapture! |
a |
| Throws | |
|---|---|
java.lang.NullPointerException: java.lang.NullPointerException |
if given activity is null |
androidx.test.runner.screenshot.Screenshot.ScreenShotException: androidx.test.runner.screenshot.Screenshot.ScreenShotException |
If there was an error capturing the screenshot |
java-static fun capture(view: View): ScreenCapture!
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.
| Returns | |
|---|---|
ScreenCapture! |
|
| Throws | |
|---|---|
java.lang.NullPointerException: java.lang.NullPointerException |
if given view is null |
androidx.test.runner.screenshot.Screenshot.ScreenShotException: androidx.test.runner.screenshot.Screenshot.ScreenShotException |
If there was an error capturing the screenshot |
java-static fun setScreenshotProcessors(
screenCaptureProcessors: (Mutable)Set<ScreenCaptureProcessor!>!
): Unit
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 | |
|---|---|
screenCaptureProcessors: (Mutable)Set<ScreenCaptureProcessor!>! |
the set of |