Skip to content

Commit 67ffa89

Browse files
Merge pull request #72 from sergio-sastre/release/2.0.0-beta03
Release/2.0.0 beta03
2 parents ba918d1 + 9174053 commit 67ffa89

File tree

52 files changed

+1159
-407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1159
-407
lines changed

README.md

Lines changed: 172 additions & 87 deletions
Large diffs are not rendered by default.

dropshots/.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
/build
1+
.gradle
2+
/local.properties
3+
.DS_Store
4+
/build
5+
/captures
6+
.externalNativeBuild
7+
.cxx
8+
local.properties
9+
10+
# idea
11+
*.iml
12+
.idea/

dropshots/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
defaultConfig {
1212
minSdk 23
1313
targetSdk 33
14-
versionCode 17
15-
versionName "2.0.0-beta02"
14+
versionCode 18
15+
versionName "2.0.0-beta03"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}
@@ -43,6 +43,7 @@ android {
4343

4444
dependencies {
4545
implementation project(':utils')
46+
implementation 'androidx.test:rules:1.5.0'
4647
api 'com.dropbox.dropshots:dropshots:0.4.0'
4748
api 'androidx.activity:activity-compose:1.7.1'
4849
}
@@ -53,7 +54,7 @@ publishing {
5354
release(MavenPublication) {
5455
groupId = 'com.github.sergio-sastre'
5556
artifactId = "dropshots"
56-
version = '2.0.0-beta02'
57+
version = '2.0.0-beta03'
5758

5859
afterEvaluate {
5960
from components.release
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<!-- The content of this manifest is needed for Dropshots to run on API 29 -->
6+
<uses-permission
7+
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
8+
android:maxSdkVersion="29"
9+
tools:node="replace" />
10+
11+
<application
12+
android:requestLegacyExternalStorage="true"
13+
tools:node="merge">
14+
</application>
15+
16+
</manifest>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package sergio.sastre.uitesting.dropshots
2+
3+
import android.Manifest
4+
import android.app.Activity
5+
import android.graphics.Bitmap
6+
import android.os.Build
7+
import android.view.View
8+
import androidx.test.rule.GrantPermissionRule
9+
import com.dropbox.dropshots.Dropshots
10+
import org.junit.rules.RuleChain
11+
import org.junit.rules.TestRule
12+
import org.junit.runner.Description
13+
import org.junit.runners.model.Statement
14+
15+
/**
16+
* Bugfix: Dropshots must grant WRITE_EXTERNAL_STORAGE to record screenshots on emulators running API 29
17+
*/
18+
class DropshotsAPI29Fix(
19+
private val dropshots: Dropshots,
20+
) : TestRule {
21+
override fun apply(base: Statement, description: Description): Statement =
22+
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
23+
RuleChain.outerRule(
24+
// needed also in the manifest. Only required for API 29
25+
GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
26+
).around(dropshots).apply(base, description)
27+
} else {
28+
dropshots.apply(base, description)
29+
}
30+
31+
fun assertSnapshot(bitmap: Bitmap, name: String) {
32+
dropshots.assertSnapshot(bitmap, name)
33+
}
34+
35+
fun assertSnapshot(activity: Activity, name: String) {
36+
dropshots.assertSnapshot(activity, name)
37+
}
38+
39+
fun assertSnapshot(view: View, name: String) {
40+
dropshots.assertSnapshot(view, name)
41+
}
42+
}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package sergio.sastre.uitesting.dropshots
22

3+
import androidx.annotation.ColorInt
4+
import com.dropbox.differ.ImageComparator
5+
import com.dropbox.differ.SimpleImageComparator
6+
import com.dropbox.dropshots.CountValidator
37
import com.dropbox.dropshots.ResultValidator
4-
import com.dropbox.dropshots.ThresholdValidator
58
import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod
69
import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig
710

811
class DropshotsConfig(
12+
val resultValidator: ResultValidator = CountValidator(0),
13+
val imageComparator: ImageComparator = SimpleImageComparator(maxDistance = 0.004f),
914
val bitmapCaptureMethod: BitmapCaptureMethod? = null,
10-
val resultValidator: ResultValidator = ThresholdValidator(0.0f),
11-
): LibraryConfig
15+
val recordScreenshots: Boolean = false,
16+
@ColorInt val backgroundColor: Int? = null,
17+
) : LibraryConfig

dropshots/src/main/java/sergio/sastre/uitesting/dropshots/DropshotsScreenshotTestRule.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ class DropshotsScreenshotTestRule(
3030
.setInitialOrientation(config.orientation)
3131
.setUiMode(config.uiMode)
3232
.setFontSize(config.fontScale)
33-
.launchConfiguredActivity()
33+
.setDisplaySize(config.displaySize)
34+
.launchConfiguredActivity(dropshotsConfig.backgroundColor)
3435
}
3536

36-
private val dropshotsRule: Dropshots by lazy {
37-
Dropshots(resultValidator = dropshotsConfig.resultValidator)
37+
private val dropshotsRule: DropshotsAPI29Fix by lazy {
38+
DropshotsAPI29Fix(
39+
Dropshots(
40+
resultValidator = dropshotsConfig.resultValidator,
41+
imageComparator = dropshotsConfig.imageComparator,
42+
recordScreenshots = dropshotsConfig.recordScreenshots,
43+
)
44+
)
3845
}
3946

4047
private var dropshotsConfig: DropshotsConfig = DropshotsConfig()
@@ -64,7 +71,7 @@ class DropshotsScreenshotTestRule(
6471
.findViewById<ViewGroup>(android.R.id.content)
6572
.getChildAt(0) as ComposeView
6673

67-
when(val bitmapCaptureMethod = dropshotsConfig.bitmapCaptureMethod){
74+
when (val bitmapCaptureMethod = dropshotsConfig.bitmapCaptureMethod) {
6875
is BitmapCaptureMethod.Canvas ->
6976
takeSnapshotWithCanvas(bitmapCaptureMethod.config, existingComposeView, name)
7077
is BitmapCaptureMethod.PixelCopy ->

inapplocale/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

inapplocale/src/main/java/sergio/sastre/uitesting/inapplocale/InAppLocaleTestRule.kt

Lines changed: 0 additions & 95 deletions
This file was deleted.

inapplocale/src/main/java/sergio/sastre/uitesting/inapplocale/OnActivityCreatedCallback.kt

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)