|
| 1 | +# Testify — Android Screenshot Testing — Fullscreen capture method |
| 2 | + |
| 3 | +<a href="https://search.maven.org/artifact/dev.testify/testify-fullscreen"><img alt="Maven Central" src="https://img.shields.io/maven-central/v/dev.testify/testify-fullscreen?color=%236e40ed&label=dev.testify%3Atestify-fullscreen"/></a> |
| 4 | + |
| 5 | +**Capture the entire device screen, including system UI, dialogs and menus.** |
| 6 | + |
| 7 | +Use the [UiAutomator's](https://developer.android.com/training/testing/other-components/ui-automator) built-in [screenshotting](https://developer.android.com/reference/androidx/test/uiautomator/UiDevice#takescreenshot) capability to capture a [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap) of the entire device. |
| 8 | + |
| 9 | +The bitmap will be generated from a PNG at 1:1 scale and 100% quality. The bitmap's size will match the full device resolution and include all system UI such as the status bar and navigation bar. |
| 10 | + |
| 11 | +As the system UI content is highly variable, you can use [ScreenshotRule.excludeStatusBar](./src/main/java/dev/testify/capture/fullscreen/provider/StatusBarExclusionRectProvider.kt) and/or [ScreenshotRule.excludeNavigationBar](./src/main/java/dev/testify/capture/fullscreen/provider/NavigationBarExclusionRectProvider.kt) to ignore the status bar and navigation bar, respectively. |
| 12 | + |
| 13 | +Though the PNG is intended to be lossless, some compression artifacts or GPU-related variance can occur. As such, it is recommended to use a small tolerance when capturing fullscreen images. |
| 14 | + |
| 15 | +You can set a comparison tolerance using [ScreenshotRule.setExactness](../../Library/src/main/java/dev/testify/ScreenshotRule.kt). |
| 16 | + |
| 17 | +# Set up testify-fullscreen |
| 18 | + |
| 19 | +**Root build.gradle** |
| 20 | + |
| 21 | +```groovy |
| 22 | +plugins { |
| 23 | + id("dev.testify") version "3.2.3" apply false |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +**settings.gradle** |
| 28 | + |
| 29 | +Ensure that `mavenCentral()` is available to both `pluginManagement` and `dependencyResolutionManagement`. |
| 30 | + |
| 31 | +**Application build.gradle** |
| 32 | +```groovy |
| 33 | +dependencies { |
| 34 | + androidTestImplementation "dev.testify:testify-fullscreen:3.2.3" |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +# Write a test |
| 39 | + |
| 40 | +In order to capture the full device screen, you must set the capture method on `ScreenshotRule` to `fullscreenCapture()`. |
| 41 | +You can do this with either `setCaptureMethod(::fullscreenCapture)` or the helper extension method `captureFullscreen()`. |
| 42 | + |
| 43 | +Additonal examples can be found in [FullscreenCaptureExampleTest.kt](../../Samples/Legacy/src/androidTest/java/dev/testify/sample/FullscreenCaptureExampleTests.kt). |
| 44 | + |
| 45 | +```kotlin |
| 46 | +class FullscreenCaptureTest { |
| 47 | + |
| 48 | + @get:Rule |
| 49 | + var rule = ScreenshotRule(MainActivity::class.java) |
| 50 | + |
| 51 | + @ScreenshotInstrumentation |
| 52 | + @Test |
| 53 | + fun fullscreen() { |
| 54 | + rule |
| 55 | + .captureFullscreen() // Set the fullscreen capture method |
| 56 | + .excludeSystemUi() // Exclude the navigation bar and status bar areas from the comparison |
| 57 | + .setExactness(0.95f) // Allow a 5% variation in color |
| 58 | + .assertSame() |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +``` |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +# License |
| 67 | + |
| 68 | + MIT License |
| 69 | + |
| 70 | + Copyright (c) 2022 ndtp |
| 71 | + |
| 72 | + Permission is hereby granted, free of charge, to any person obtaining a copy |
| 73 | + of this software and associated documentation files (the "Software"), to deal |
| 74 | + in the Software without restriction, including without limitation the rights |
| 75 | + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 76 | + copies of the Software, and to permit persons to whom the Software is |
| 77 | + furnished to do so, subject to the following conditions: |
| 78 | + |
| 79 | + The above copyright notice and this permission notice shall be included in all |
| 80 | + copies or substantial portions of the Software. |
| 81 | + |
| 82 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 83 | + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 84 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 85 | + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 86 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 87 | + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 88 | + SOFTWARE. |
0 commit comments