Skip to main content
Version: 3.2.0

Selecting an alternative capture method

Testify provides three built-in bitmap capture methods. Each method will capture slightly different results based primarily on API level. In addition, a Fullscreen Capture Method is provided as an optional extension.

The three standard capture methods available are:

  1. DrawingCache: Pulls the view's drawing cache bitmap using the deprecated View.getDrawingCache (deprecated in API level 28).
  2. Canvas: Render the view (and all of its children) to a given Canvas, using View.draw
  3. PixelCopy: Use Android's recommended PixelCopy API to capture the full screen, including elevation.
caution

For legacy compatibility reasons, DrawingCache mode is the default Testify capture method. The default will change to PixelCopy in a future release.

In addition, capture methods are extensible.

  1. Fullscreen: The Testify Fullscreen Capture Method can be used to capture UI elements presented outside of your root view. This includes elements rendered in a different Window such as dialogs, alerts, notifications, or overlays.

Code Configuration

To configure a custom capture method, provide a function that conforms to the CaptureMethod signature. A CaptureMethod returns a Bitmap from the provided Activity and View.

typealias CaptureMethod = (activity: Activity, targetView: View?) -> Bitmap?
tip

See Customizing the captured bitmap for an example of how to provide your own CaptureMethod.

Or, you can specify one of the provided methods from the dev.testify.core.processor.capture package:

  • ::canvasCapture: Canvas
  • ::createBitmapFromDrawingCache: DrawingCache
  • ::pixelCopyCapture: PixelCopy
@ScreenshotInstrumentation
@Test
fun testDefault() {
rule
.configure {
captureMethod = ::canvasCapture
}
.assertSame()
}

Manifest Configuration

danger

testify-pixelcopy-capture and testify-canvas-capture are deprecated and will be removed in a future version.

Alternatively, you can also select an alternative capture method in your manifest.

  • testify-pixelcopy-capture: PixelCopy capture method
  • testify-canvas-capture: Canvas capture method
<manifest package="dev.testify.sample"
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<meta-data android:name="testify-canvas-capture" android:value="true" />
</application>

</manifest>