Skip to content

Commit 21b43ac

Browse files
committed
Add boilerplate for Ktx library
1 parent 70cb5a2 commit 21b43ac

3 files changed

Lines changed: 192 additions & 10 deletions

File tree

Ext/Ktx/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.

Ext/Ktx/build.gradle

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'kotlin-android'
4+
id 'org.jetbrains.dokka'
5+
}
6+
7+
ext {
8+
pom = [
9+
publishedGroupId : 'dev.testify',
10+
artifact : 'testify-ktx',
11+
libraryName : 'testify-ktx',
12+
libraryDescription: 'Kotlin extension methods and helpers for Android Testify',
13+
siteUrl : 'https://github.com/ndtp/android-testify',
14+
gitUrl : 'https://github.com/ndtp/android-testify.git',
15+
licenseName : 'The MIT License',
16+
licenseUrl : 'https://opensource.org/licenses/MIT',
17+
author : 'ndtp'
18+
]
19+
}
20+
21+
version = project.findProperty("testify_version") ?: "0.0.1-SNAPSHOT"
22+
group = pom.publishedGroupId
23+
archivesBaseName = pom.artifact
24+
25+
android {
26+
namespace "dev.testify.ktx"
27+
28+
lintOptions {
29+
abortOnError true
30+
warningsAsErrors true
31+
textOutput 'stdout'
32+
textReport true
33+
xmlReport false
34+
}
35+
36+
defaultConfig {
37+
compileSdk libs.versions.compileSdk.get().toInteger()
38+
minSdkVersion libs.versions.minSdk.get().toInteger()
39+
targetSdkVersion libs.versions.targetSdk.get().toInteger()
40+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
41+
multiDexEnabled = true
42+
kotlinOptions {
43+
allWarningsAsErrors = true
44+
}
45+
}
46+
47+
libraryVariants.all { variant ->
48+
variant.outputs.all {
49+
outputFileName = "${archivesBaseName}-${version}.aar"
50+
}
51+
}
52+
53+
testOptions {
54+
unitTests.returnDefaultValues = true
55+
unitTests.all {
56+
testLogging {
57+
events "passed", "skipped", "failed", "standardOut", "standardError"
58+
outputs.upToDateWhen { false }
59+
showStandardStreams = true
60+
}
61+
}
62+
}
63+
64+
kotlinOptions {
65+
jvmTarget = '21'
66+
}
67+
compileOptions {
68+
sourceCompatibility JavaVersion.VERSION_21
69+
targetCompatibility JavaVersion.VERSION_21
70+
}
71+
72+
dependencies {
73+
implementation libs.androidx.monitor
74+
implementation libs.androidx.rules
75+
implementation libs.androidx.uiautomator
76+
implementation libs.core.ktx
77+
}
78+
79+
publishing {
80+
singleVariant("release") {
81+
// if you don't want sources/javadoc, remove these lines
82+
withSourcesJar()
83+
withJavadocJar()
84+
}
85+
}
86+
}
87+
88+
afterEvaluate {
89+
apply from: "../../publish.build.gradle"
90+
}
91+
92+
apply from: '../../ktlint.gradle'

settings.gradle

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@ dependencyResolutionManagement {
1717
}
1818
}
1919

20-
include ':LegacySample'
21-
include ':FlixSample'
20+
include ':Accessibility'
21+
include ':ComposeExtensions'
2222
include ':FlixLibrary'
23+
include ':FlixSample'
24+
include ':FullscreenCaptureMethod'
2325
include ':GmdSample'
24-
includeBuild("./Plugins/Gradle") { name = "Plugin" }
26+
include ':Ktx'
27+
include ':LegacySample'
2528
include ':Library'
26-
include ':ComposeExtensions'
27-
include ':FullscreenCaptureMethod'
28-
include ':Accessibility'
29+
includeBuild("./Plugins/Gradle") { name = "Plugin" }
2930

30-
project(':ComposeExtensions').projectDir = new File("./Ext/Compose")
31-
project(':FullscreenCaptureMethod').projectDir = new File("./Ext/Fullscreen")
3231
project(':Accessibility').projectDir = new File("./Ext/Accessibility")
33-
project(':LegacySample').projectDir = new File("./Samples/Legacy")
34-
project(':FlixSample').projectDir = new File("./Samples/Flix")
32+
project(':ComposeExtensions').projectDir = new File("./Ext/Compose")
3533
project(':FlixLibrary').projectDir = new File("./Samples/Flix/FlixLibrary")
34+
project(':FlixSample').projectDir = new File("./Samples/Flix")
35+
project(':FullscreenCaptureMethod').projectDir = new File("./Ext/Fullscreen")
3636
project(':GmdSample').projectDir = new File("./Samples/Gmd")
37+
project(':Ktx').projectDir = new File("./Ext/Ktx")
38+
project(':LegacySample').projectDir = new File("./Samples/Legacy")

0 commit comments

Comments
 (0)