From cef882989244c00cf046116faa035f4682fb61d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Thu, 15 Aug 2024 21:30:45 +0200 Subject: [PATCH 1/7] CrossLibrary: Add record options for Roborazzi --- .../uitesting/mapper/roborazzi/wrapper/RecordOptions.kt | 7 +++++++ .../uitesting/mapper/roborazzi/wrapper/RoborazziOptions.kt | 1 + roborazzi/build.gradle | 2 +- .../roborazzi/config/RoborazziSharedTestAdapter.kt | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RecordOptions.kt diff --git a/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RecordOptions.kt b/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RecordOptions.kt new file mode 100644 index 0000000..1b3ea96 --- /dev/null +++ b/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RecordOptions.kt @@ -0,0 +1,7 @@ +package sergio.sastre.uitesting.mapper.roborazzi.wrapper + +data class RecordOptions( + val resizeScale: Double = + checkNotNull(System.getProperty("roborazzi.record.resizeScale", "1.0")).toDouble(), + val applyDeviceCrop: Boolean = false +) diff --git a/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RoborazziOptions.kt b/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RoborazziOptions.kt index 7ac9411..cccaa05 100644 --- a/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RoborazziOptions.kt +++ b/mapper-roborazzi/src/main/java/sergio/sastre/uitesting/mapper/roborazzi/wrapper/RoborazziOptions.kt @@ -3,5 +3,6 @@ package sergio.sastre.uitesting.mapper.roborazzi.wrapper data class RoborazziOptions( val captureType: CaptureType = CaptureType.Screenshot, val compareOptions: CompareOptions = CompareOptions(), + val recordOptions: RecordOptions = RecordOptions(), val contextData: Map = emptyMap(), ) diff --git a/roborazzi/build.gradle b/roborazzi/build.gradle index e95d887..f27bece 100644 --- a/roborazzi/build.gradle +++ b/roborazzi/build.gradle @@ -51,7 +51,7 @@ dependencies { implementation project(':robolectric') implementation project(':mapper-roborazzi') - api 'io.github.takahirom.roborazzi:roborazzi:1.12.0' + api 'io.github.takahirom.roborazzi:roborazzi:1.26.0' api 'androidx.test.espresso:espresso-core:3.5.1' api 'org.hamcrest:hamcrest:2.2' diff --git a/roborazzi/src/main/java/sergio/sastre/uitesting/roborazzi/config/RoborazziSharedTestAdapter.kt b/roborazzi/src/main/java/sergio/sastre/uitesting/roborazzi/config/RoborazziSharedTestAdapter.kt index 6261db5..7c403d2 100644 --- a/roborazzi/src/main/java/sergio/sastre/uitesting/roborazzi/config/RoborazziSharedTestAdapter.kt +++ b/roborazzi/src/main/java/sergio/sastre/uitesting/roborazzi/config/RoborazziSharedTestAdapter.kt @@ -72,10 +72,17 @@ internal class RoborazziSharedTestAdapter( imageComparator = asImageComparator(), ) + val adaptedRecordOptions: RoborazziOptions.RecordOptions = + RoborazziOptions.RecordOptions( + resizeScale = it.recordOptions.resizeScale, + applyDeviceCrop = it.recordOptions.applyDeviceCrop, + ) + return RoborazziOptions( captureType = adaptedCaptureType, compareOptions = adaptedCompareOptions, contextData = it.contextData, + recordOptions = adaptedRecordOptions, ) } } From 8d0f33feb95cda1f33b1d74837e990489d66757b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Sun, 11 Aug 2024 19:42:03 +0200 Subject: [PATCH 2/7] Upgrade android-testify --- android-testify/build.gradle | 2 +- .../android_testify/AndroidTestifyConfig.kt | 15 ++- ...dTestifyScreenshotTestRuleForComposable.kt | 52 --------- ...mposableScreenshotRuleWithConfiguration.kt | 1 + .../android_testify/ScreenshotRuleExt.kt | 2 +- ...eenshotRuleWithConfigurationForFragment.kt | 1 + .../ScreenshotRuleWithConfigurationForView.kt | 1 + .../ActivityScenarioForComposableRuleExt.kt | 16 +++ .../ScreenshotScenarioRuleExt.kt | 96 ++++++++++++++++ .../ScreenshotScenarioRuleForComposable.kt | 103 ++++++++++++++++++ .../ScreenshotScenarioRuleForFragment.kt | 88 +++++++++++++++ .../ScreenshotScenarioRuleForView.kt} | 52 ++++++--- ...hotLibraryTestRuleForComposableProvider.kt | 10 +- ...creenshotLibraryTestRuleForViewProvider.kt | 10 +- 14 files changed, 369 insertions(+), 80 deletions(-) delete mode 100644 android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForComposable.kt create mode 100644 android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ActivityScenarioForComposableRuleExt.kt create mode 100644 android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt create mode 100644 android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt create mode 100644 android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForFragment.kt rename android-testify/src/main/java/sergio/sastre/uitesting/android_testify/{AndroidTestifyScreenshotTestRuleForView.kt => screenshotscenario/ScreenshotScenarioRuleForView.kt} (66%) diff --git a/android-testify/build.gradle b/android-testify/build.gradle index 033af46..cd384c7 100644 --- a/android-testify/build.gradle +++ b/android-testify/build.gradle @@ -52,7 +52,7 @@ android { dependencies { implementation project(':utils') implementation 'androidx.test:rules:1.5.0' - api 'dev.testify:testify:2.0.0' + api 'dev.testify:testify:3.1.0' api 'androidx.activity:activity-compose:1.8.2' } diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt index ed41c5d..5fa7a23 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt @@ -1,6 +1,10 @@ package sergio.sastre.uitesting.android_testify +import android.graphics.Rect +import android.view.ViewGroup import androidx.annotation.ColorInt +import dev.testify.CompareMethod +import dev.testify.core.ExclusionRectProvider import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig @@ -8,8 +12,17 @@ class AndroidTestifyConfig( val bitmapCaptureMethod: BitmapCaptureMethod? = null, val exactness: Float = 0.9f, val enableReporter: Boolean = false, - val initialTouchMode: Boolean = false, val generateDiffs: Boolean = true, val animationsDisabled: Boolean = true, + val hideCursor: Boolean = true, + val hidePasswords: Boolean = true, + val hideScrollbars: Boolean = true, + val hideSoftKeyboard: Boolean = true, + val hideTextSuggestions: Boolean = true, + val useSoftwareRenderer: Boolean = true, + val exclusionRects: MutableSet = HashSet(), + val exclusionRectProvider: ExclusionRectProvider? = null, + val compareMethod: CompareMethod? = null, + val pauseForInspection: Boolean = false, @ColorInt val backgroundColor: Int? = null, ) : LibraryConfig diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForComposable.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForComposable.kt deleted file mode 100644 index 7ae05d2..0000000 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForComposable.kt +++ /dev/null @@ -1,52 +0,0 @@ -package sergio.sastre.uitesting.android_testify - -import androidx.compose.runtime.Composable -import org.junit.runner.Description -import org.junit.runners.model.Statement -import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig -import sergio.sastre.uitesting.utils.crosslibrary.config.ScreenshotConfigForComposable -import sergio.sastre.uitesting.utils.crosslibrary.testrules.ScreenshotTestRuleForComposable - -class AndroidTestifyScreenshotTestRuleForComposable( - override val config: ScreenshotConfigForComposable = ScreenshotConfigForComposable(), -) : ScreenshotTestRuleForComposable(config) { - - private val screenshotRule: ComposableScreenshotRuleWithConfiguration by lazy { - ComposableScreenshotRuleWithConfiguration( - exactness = androidTestifyConfig.exactness, - activityBackgroundColor = androidTestifyConfig.backgroundColor, - enableReporter = androidTestifyConfig.enableReporter, - initialTouchMode = androidTestifyConfig.initialTouchMode, - config = config.toComposableConfig(), - ) - } - - private var androidTestifyConfig: AndroidTestifyConfig = AndroidTestifyConfig() - - override fun apply(base: Statement, description: Description): Statement { - return screenshotRule.apply(base, description) - } - - override fun snapshot(composable: @Composable () -> Unit) { - screenshotRule - .setCompose { composable() } - .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) - .generateDiffs(androidTestifyConfig.generateDiffs) - .assertSame() - } - - override fun snapshot(name: String?, composable: @Composable () -> Unit) { - screenshotRule - .setCompose { composable() } - .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) - .generateDiffs(androidTestifyConfig.generateDiffs) - .assertSame(name = name) - } - - override fun configure(config: LibraryConfig): ScreenshotTestRuleForComposable { - if (config is AndroidTestifyConfig){ - androidTestifyConfig = config - } - return this - } -} diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt index af20775..8b38ef6 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt @@ -27,6 +27,7 @@ import sergio.sastre.uitesting.utils.common.Orientation import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit +@Deprecated("For Android-Testify 3.0.0+, use ScreenshotScenarioRuleForComposable instead") open class ComposableScreenshotRuleWithConfiguration( exactness: Float = 0.9f, initialTouchMode: Boolean = false, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleExt.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleExt.kt index c5a5e29..46c3fc7 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleExt.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleExt.kt @@ -51,7 +51,7 @@ fun ScreenshotRule.waitForIdleSync(): ScreenshotRule = appl // We need to ensure the view is attached to the screenshotRule activity window for testify to // take the screenshot. This is especially important for dialogs -internal fun ScreenshotRule.setViewUnderTest( +internal fun ScreenshotRule.setDialogViewUnderTest( view: View, ): ScreenshotRule = apply { setScreenshotViewProvider { diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt index 8652ee8..7dca104 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt @@ -15,6 +15,7 @@ import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioConfigurat import sergio.sastre.uitesting.utils.common.Orientation import sergio.sastre.uitesting.utils.fragmentscenario.FragmentConfigItem +@Deprecated("For Android-Testify 3.0.0+, use ScreenshotScenarioRuleForFragment instead") class ScreenshotRuleWithConfigurationForFragment( exactness: Float? = null, enableReporter: Boolean = false, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt index d0612ab..564a161 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt @@ -10,6 +10,7 @@ import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioConfigurat import sergio.sastre.uitesting.utils.activityscenario.ViewConfigItem import sergio.sastre.uitesting.utils.common.Orientation +@Deprecated("For Android-Testify 3.0.0+, use ScreenshotScenarioRuleForView instead") class ScreenshotRuleWithConfigurationForView( exactness: Float? = null, enableReporter: Boolean = false, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ActivityScenarioForComposableRuleExt.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ActivityScenarioForComposableRuleExt.kt new file mode 100644 index 0000000..265dae9 --- /dev/null +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ActivityScenarioForComposableRuleExt.kt @@ -0,0 +1,16 @@ +package sergio.sastre.uitesting.android_testify.screenshotscenario + +import androidx.activity.compose.setContent +import androidx.compose.runtime.Composable +import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioForComposableRule + +fun ActivityScenarioForComposableRule.setContent( + composable: @Composable () -> Unit, +): ActivityScenarioForComposableRule { + this.activityScenario + .onActivity { + it.setContent { composable.invoke() } + } + + return this +} diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt new file mode 100644 index 0000000..39c2e6a --- /dev/null +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt @@ -0,0 +1,96 @@ +package sergio.sastre.uitesting.android_testify.screenshotscenario + +import android.app.Activity +import android.graphics.Bitmap +import android.view.View +import android.view.ViewGroup +import androidx.core.view.drawToBitmap +import androidx.test.platform.app.InstrumentationRegistry +import dev.testify.TestDescription +import dev.testify.TestifyFeatures +import dev.testify.scenario.ScreenshotScenarioRule +import dev.testify.testDescription +import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod +import sergio.sastre.uitesting.utils.utils.drawToBitmapWithElevation +import sergio.sastre.uitesting.utils.utils.waitForMeasuredView + +fun ScreenshotScenarioRule.assertSame(name: String?) { + if (name != null) { + // this is how to change the name of the screenshot file + InstrumentationRegistry.getInstrumentation().testDescription = TestDescription( + methodName = name, + testClass = InstrumentationRegistry.getInstrumentation().testDescription.testClass + ) + } + assertSame() +} + +fun ScreenshotScenarioRule.waitForIdleSync(): ScreenshotScenarioRule = apply { + InstrumentationRegistry.getInstrumentation().waitForIdleSync() +} + +internal fun ScreenshotScenarioRule.setDialogViewUnderTest( + view: View, +): ScreenshotScenarioRule = apply { + setScreenshotViewProvider { + InstrumentationRegistry.getInstrumentation().run { + runOnMainSync { + (view.parent as ViewGroup?)?.removeAllViews() + } + waitForIdleSync() + + runOnMainSync { + (activity.window.decorView as ViewGroup).addView(view) + } + waitForIdleSync() + } + waitForMeasuredView { view } + } +} + +internal fun ScreenshotScenarioRule.setViewUnderTest( + view: View, +): ScreenshotScenarioRule = apply { + setScreenshotViewProvider { + waitForMeasuredView { view } + } +} + +internal fun ScreenshotScenarioRule.setComposeViewUnderTest( + view: View, +): ScreenshotScenarioRule = apply { + setScreenshotViewProvider { view } +} + +internal fun ScreenshotScenarioRule.setBitmapCaptureMethod( + bitmapCaptureMethod: BitmapCaptureMethod?, +): ScreenshotScenarioRule = apply { + when (bitmapCaptureMethod) { + is BitmapCaptureMethod.Canvas -> { + fun canvas(activity: Activity, targetView: View?): Bitmap? { + return targetView?.drawToBitmap(bitmapCaptureMethod.config) + } + configure { captureMethod = ::canvas } + } + + is BitmapCaptureMethod.PixelCopy -> { + fun pixelCopy(activity: Activity, targetView: View?): Bitmap? { + return targetView?.drawToBitmapWithElevation( + activity = activity, + config = bitmapCaptureMethod.config + ) + } + configure { captureMethod = ::pixelCopy } + } + + null -> { /*no-op*/ } + } +} + +fun ScreenshotScenarioRule.generateDiffs( + generate: Boolean, +): ScreenshotScenarioRule = apply { + if (generate) { + TestifyFeatures.GenerateDiffs.setEnabled(true) + } +} diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt new file mode 100644 index 0000000..dffa854 --- /dev/null +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt @@ -0,0 +1,103 @@ +package sergio.sastre.uitesting.android_testify.screenshotscenario + +import androidx.compose.runtime.Composable +import dev.testify.core.TestifyConfiguration +import dev.testify.scenario.ScreenshotScenarioRule +import org.junit.rules.RuleChain +import org.junit.runner.Description +import org.junit.runners.model.Statement +import sergio.sastre.uitesting.android_testify.AndroidTestifyConfig +import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioForComposableRule +import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig +import sergio.sastre.uitesting.utils.crosslibrary.config.ScreenshotConfigForComposable +import sergio.sastre.uitesting.utils.crosslibrary.testrules.ScreenshotTestRuleForComposable +import sergio.sastre.uitesting.utils.testrules.animations.DisableAnimationsRule + +class ScreenshotScenarioRuleForComposable( + override val config: ScreenshotConfigForComposable = ScreenshotConfigForComposable(), +) : ScreenshotTestRuleForComposable(config) { + + private val screenshotRule: ScreenshotScenarioRule by lazy { + ScreenshotScenarioRule( + configuration = TestifyConfiguration( + exactness = androidTestifyConfig.exactness, + hideCursor = androidTestifyConfig.hideCursor, + hidePasswords = androidTestifyConfig.hidePasswords, + hideScrollbars = androidTestifyConfig.hideScrollbars, + hideSoftKeyboard = androidTestifyConfig.hideSoftKeyboard, + hideTextSuggestions = androidTestifyConfig.hideTextSuggestions, + useSoftwareRenderer = androidTestifyConfig.useSoftwareRenderer, + exclusionRects = androidTestifyConfig.exclusionRects, + exclusionRectProvider = androidTestifyConfig.exclusionRectProvider, + pauseForInspection = androidTestifyConfig.pauseForInspection, + compareMethod = androidTestifyConfig.compareMethod, + ), + enableReporter = androidTestifyConfig.enableReporter, + ) + } + + // Use only for the context and inflate methods, because for ScreenshotRule it would crash... + private val activityScenarioRule by lazy { + ActivityScenarioForComposableRule( + backgroundColor = androidTestifyConfig.backgroundColor, + config = config.toComposableConfig() + ) + } + + private var androidTestifyConfig: AndroidTestifyConfig = AndroidTestifyConfig() + + override fun apply( + base: Statement, + description: Description, + ): Statement = + when (androidTestifyConfig.animationsDisabled) { + true -> RuleChain + .outerRule(DisableAnimationsRule()) + .around(activityScenarioRule) + .around(screenshotRule) + .apply(base, description) + false -> RuleChain + .outerRule(activityScenarioRule) + .around(screenshotRule) + .apply(base, description) + } + + override fun snapshot(composable: @Composable () -> Unit) { + screenshotRule + .withScenario(activityScenarioRule.activityScenario) + + val composeView = + activityScenarioRule + .setContent(composable) + .composeView + + screenshotRule + .setComposeViewUnderTest(composeView) + .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) + .generateDiffs(androidTestifyConfig.generateDiffs) + .assertSame(null) + } + + override fun snapshot(name: String?, composable: @Composable () -> Unit) { + screenshotRule + .withScenario(activityScenarioRule.activityScenario) + + val composeView = + activityScenarioRule + .setContent(composable) + .composeView + + screenshotRule + .setComposeViewUnderTest(composeView) + .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) + .generateDiffs(androidTestifyConfig.generateDiffs) + .assertSame(name = name) + } + + override fun configure(config: LibraryConfig): ScreenshotTestRuleForComposable { + if (config is AndroidTestifyConfig) { + androidTestifyConfig = config + } + return this + } +} diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForFragment.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForFragment.kt new file mode 100644 index 0000000..7e9d16a --- /dev/null +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForFragment.kt @@ -0,0 +1,88 @@ +package sergio.sastre.uitesting.android_testify.screenshotscenario + +import android.app.Activity +import android.os.Bundle +import androidx.activity.viewModels +import androidx.annotation.RestrictTo +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.fragment.app.FragmentFactory +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import androidx.test.core.app.ActivityScenario +import dev.testify.core.TestifyConfiguration +import dev.testify.scenario.ScreenshotScenarioRule + +class ScreenshotScenarioRuleForFragment( + configuration: TestifyConfiguration, + enableReporter: Boolean = false, + private val fragmentClass: Class, + private val fragmentArgs: Bundle? = null, + private val factory: FragmentFactory? = null, +) : ScreenshotScenarioRule( + enableReporter = enableReporter, + configuration = configuration +) { + + private companion object { + const val FRAGMENT_TAG = "Android-Testify-Fragment" + } + + override fun withScenario(scenario: ActivityScenario): ScreenshotScenarioRule { + return super.withScenario(scenario).also { setFragmentForScreenshot() } + } + + private fun setFragmentForScreenshot(){ + setViewModifications { + if (factory != null) { + FragmentFactoryHolderViewModel.getInstance(activity as FragmentActivity).fragmentFactory = factory + (activity as FragmentActivity).supportFragmentManager.fragmentFactory = factory + } + + val fragment = (activity as FragmentActivity).supportFragmentManager.fragmentFactory + .instantiate(requireNotNull(fragmentClass.classLoader), fragmentClass.name) + + if (fragmentArgs != null) { + fragment.arguments = fragmentArgs + } + + (activity as FragmentActivity).supportFragmentManager.beginTransaction() + .add( + android.R.id.content, + fragment, + FRAGMENT_TAG + ) + .commitNow() + + // by default, the fragment is what we screenshot + }.setScreenshotViewProvider { + (activity as FragmentActivity).supportFragmentManager.findFragmentByTag(FRAGMENT_TAG)!!.requireView() + } + } + + @RestrictTo(RestrictTo.Scope.LIBRARY) + internal class FragmentFactoryHolderViewModel : ViewModel() { + var fragmentFactory: FragmentFactory? = null + + override fun onCleared() { + super.onCleared() + fragmentFactory = null + } + + companion object { + fun getInstance(activity: FragmentActivity): FragmentFactoryHolderViewModel { + val viewModel: FragmentFactoryHolderViewModel by activity.viewModels { + object : ViewModelProvider.Factory { + @Suppress("UNCHECKED_CAST") + override fun create(modelClass: Class): T { + val viewModel = + FragmentFactoryHolderViewModel() + return viewModel as T + } + } + } + return viewModel + } + } + } +} \ No newline at end of file diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForView.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt similarity index 66% rename from android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForView.kt rename to android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt index da8c5a5..f61deb4 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyScreenshotTestRuleForView.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt @@ -1,35 +1,46 @@ -package sergio.sastre.uitesting.android_testify +package sergio.sastre.uitesting.android_testify.screenshotscenario import android.app.Dialog import android.content.Context import android.view.View import androidx.recyclerview.widget.RecyclerView +import dev.testify.core.TestifyConfiguration +import dev.testify.scenario.ScreenshotScenarioRule import org.junit.rules.RuleChain import org.junit.runner.Description import org.junit.runners.model.Statement +import sergio.sastre.uitesting.android_testify.AndroidTestifyConfig import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioForViewRule import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig import sergio.sastre.uitesting.utils.crosslibrary.config.ScreenshotConfigForView import sergio.sastre.uitesting.utils.crosslibrary.testrules.ScreenshotTestRuleForView import sergio.sastre.uitesting.utils.testrules.animations.DisableAnimationsRule -import sergio.sastre.uitesting.utils.utils.inflateAndWaitForIdle import sergio.sastre.uitesting.utils.utils.waitForMeasuredView as androidUiTestingUtilsMeasuredView import sergio.sastre.uitesting.utils.utils.waitForMeasuredViewHolder as androidUiTestingUtilsMeasuredViewHolder import sergio.sastre.uitesting.utils.utils.waitForMeasuredDialog as androidUiTestingUtilsMeasuredDialog -class AndroidTestifyScreenshotTestRuleForView( +class ScreenshotScenarioRuleForView( override val config: ScreenshotConfigForView = ScreenshotConfigForView(), ) : ScreenshotTestRuleForView(config) { private var androidTestifyConfig: AndroidTestifyConfig = AndroidTestifyConfig() - private val screenshotRule: ScreenshotRuleWithConfigurationForView by lazy { - ScreenshotRuleWithConfigurationForView( - exactness = androidTestifyConfig.exactness, - activityBackgroundColor = androidTestifyConfig.backgroundColor, + private val screenshotRule: ScreenshotScenarioRule by lazy { + ScreenshotScenarioRule( + configuration = TestifyConfiguration( + exactness = androidTestifyConfig.exactness, + hideCursor = androidTestifyConfig.hideCursor, + hidePasswords = androidTestifyConfig.hidePasswords, + hideScrollbars = androidTestifyConfig.hideScrollbars, + hideSoftKeyboard = androidTestifyConfig.hideSoftKeyboard, + hideTextSuggestions = androidTestifyConfig.hideTextSuggestions, + useSoftwareRenderer = androidTestifyConfig.useSoftwareRenderer, + exclusionRects = androidTestifyConfig.exclusionRects, + exclusionRectProvider = androidTestifyConfig.exclusionRectProvider, + pauseForInspection = androidTestifyConfig.pauseForInspection, + compareMethod = androidTestifyConfig.compareMethod, + ), enableReporter = androidTestifyConfig.enableReporter, - initialTouchMode = androidTestifyConfig.initialTouchMode, - config = config.toViewConfig() ) } @@ -62,8 +73,10 @@ class AndroidTestifyScreenshotTestRuleForView( .apply(base, description) } - override fun inflate(layoutId: Int): View = - activityScenarioRule.activity.inflateAndWaitForIdle(layoutId) + override fun inflate(layoutId: Int): View { + screenshotRule.withScenario(activityScenarioRule.activityScenario) + return activityScenarioRule.inflateAndWaitForIdle(layoutId) + } override fun waitForMeasuredView(actionToDo: () -> View): View { viewToScreenshot = androidUiTestingUtilsMeasuredView { actionToDo() } @@ -81,18 +94,18 @@ class AndroidTestifyScreenshotTestRuleForView( } override fun snapshotDialog(name: String?, dialog: Dialog) { - takeSnapshot(name = name) + takeDialogSnapshot(name = name) } override fun snapshotView(name: String?, view: View) { - takeSnapshot(name = name) + takeViewSnapshot(name = name) } override fun snapshotViewHolder(name: String?, viewHolder: RecyclerView.ViewHolder) { - takeSnapshot(name = name) + takeViewSnapshot(name = name) } - private fun takeSnapshot(name:String?){ + private fun takeViewSnapshot(name:String?){ screenshotRule .setViewUnderTest(viewToScreenshot!!) .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) @@ -101,6 +114,15 @@ class AndroidTestifyScreenshotTestRuleForView( .assertSame(name = name) } + private fun takeDialogSnapshot(name:String?){ + screenshotRule + .setDialogViewUnderTest(viewToScreenshot!!) + .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) + .generateDiffs(androidTestifyConfig.generateDiffs) + .waitForIdleSync() + .assertSame(name = name) + } + override fun configure(config: LibraryConfig): ScreenshotTestRuleForView = apply { if (config is AndroidTestifyConfig) { androidTestifyConfig = config diff --git a/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForComposableProvider.kt b/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForComposableProvider.kt index e4f1717..b39421d 100644 --- a/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForComposableProvider.kt +++ b/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForComposableProvider.kt @@ -6,11 +6,11 @@ import sergio.sastre.uitesting.utils.crosslibrary.testrules.ScreenshotTestRuleFo interface ScreenshotLibraryTestRuleForComposableProvider { companion object ScreenshotTestRuleClassPath { - const val PAPARAZZI = "sergio.sastre.uitesting.paparazzi.PaparazziScreenshotTestRuleForComposable"; - const val SHOT = "sergio.sastre.uitesting.shot.ShotScreenshotTestRuleForComposable"; - const val DROPSHOTS = "sergio.sastre.uitesting.dropshots.DropshotsScreenshotTestRuleForComposable"; - const val ANDROID_TESTIFY = "sergio.sastre.uitesting.android_testify.AndroidTestifyScreenshotTestRuleForComposable"; - const val ROBORAZZI = "sergio.sastre.uitesting.roborazzi.RoborazziScreenshotTestRuleForComposable"; + const val PAPARAZZI = "sergio.sastre.uitesting.paparazzi.PaparazziScreenshotTestRuleForComposable" + const val SHOT = "sergio.sastre.uitesting.shot.ShotScreenshotTestRuleForComposable" + const val DROPSHOTS = "sergio.sastre.uitesting.dropshots.DropshotsScreenshotTestRuleForComposable" + const val ANDROID_TESTIFY = "sergio.sastre.uitesting.android_testify.screenshotscenario.ScreenshotScenarioRuleForComposable" + const val ROBORAZZI = "sergio.sastre.uitesting.roborazzi.RoborazziScreenshotTestRuleForComposable" } val config: ScreenshotConfigForComposable diff --git a/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForViewProvider.kt b/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForViewProvider.kt index 55598e7..3f6cc91 100644 --- a/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForViewProvider.kt +++ b/utils/src/main/java/sergio/sastre/uitesting/utils/crosslibrary/testrules/providers/ScreenshotLibraryTestRuleForViewProvider.kt @@ -6,11 +6,11 @@ import sergio.sastre.uitesting.utils.crosslibrary.testrules.ScreenshotTestRuleFo interface ScreenshotLibraryTestRuleForViewProvider { companion object ScreenshotTestRuleClassPath { - const val PAPARAZZI = "sergio.sastre.uitesting.paparazzi.PaparazziScreenshotTestRuleForView"; - const val SHOT = "sergio.sastre.uitesting.shot.ShotScreenshotTestRuleForView"; - const val ANDROID_TESTIFY = "sergio.sastre.uitesting.android_testify.AndroidTestifyScreenshotTestRuleForView"; - const val DROPSHOTS = "sergio.sastre.uitesting.dropshots.DropshotsScreenshotTestRuleForView"; - const val ROBORAZZI = "sergio.sastre.uitesting.roborazzi.RoborazziScreenshotTestRuleForView"; + const val PAPARAZZI = "sergio.sastre.uitesting.paparazzi.PaparazziScreenshotTestRuleForView" + const val SHOT = "sergio.sastre.uitesting.shot.ShotScreenshotTestRuleForView" + const val ANDROID_TESTIFY = "sergio.sastre.uitesting.android_testify.screenshotscenario.ScreenshotScenarioRuleForView" + const val DROPSHOTS = "sergio.sastre.uitesting.dropshots.DropshotsScreenshotTestRuleForView" + const val ROBORAZZI = "sergio.sastre.uitesting.roborazzi.RoborazziScreenshotTestRuleForView" } val config: ScreenshotConfigForView From 2f01897e35c9433b7ebce95e1e8faf4ef1ef8c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Sun, 8 Sep 2024 08:59:50 +0200 Subject: [PATCH 3/7] Upgrade Android-testify version --- android-testify/build.gradle | 2 +- .../ComposableScreenshotRuleWithConfiguration.kt | 1 - .../ScreenshotRuleWithConfigurationForFragment.kt | 1 - .../android_testify/ScreenshotRuleWithConfigurationForView.kt | 1 - .../screenshotscenario/ScreenshotScenarioRuleForView.kt | 3 +++ 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android-testify/build.gradle b/android-testify/build.gradle index cd384c7..df7fdc8 100644 --- a/android-testify/build.gradle +++ b/android-testify/build.gradle @@ -52,7 +52,7 @@ android { dependencies { implementation project(':utils') implementation 'androidx.test:rules:1.5.0' - api 'dev.testify:testify:3.1.0' + api 'dev.testify:testify:3.2.0' api 'androidx.activity:activity-compose:1.8.2' } diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt index 8b38ef6..af20775 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ComposableScreenshotRuleWithConfiguration.kt @@ -27,7 +27,6 @@ import sergio.sastre.uitesting.utils.common.Orientation import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit -@Deprecated("For Android-Testify 3.0.0+, use ScreenshotScenarioRuleForComposable instead") open class ComposableScreenshotRuleWithConfiguration( exactness: Float = 0.9f, initialTouchMode: Boolean = false, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt index 7dca104..8652ee8 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForFragment.kt @@ -15,7 +15,6 @@ import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioConfigurat import sergio.sastre.uitesting.utils.common.Orientation import sergio.sastre.uitesting.utils.fragmentscenario.FragmentConfigItem -@Deprecated("For Android-Testify 3.0.0+, use ScreenshotScenarioRuleForFragment instead") class ScreenshotRuleWithConfigurationForFragment( exactness: Float? = null, enableReporter: Boolean = false, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt index 564a161..d0612ab 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/ScreenshotRuleWithConfigurationForView.kt @@ -10,7 +10,6 @@ import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioConfigurat import sergio.sastre.uitesting.utils.activityscenario.ViewConfigItem import sergio.sastre.uitesting.utils.common.Orientation -@Deprecated("For Android-Testify 3.0.0+, use ScreenshotScenarioRuleForView instead") class ScreenshotRuleWithConfigurationForView( exactness: Float? = null, enableReporter: Boolean = false, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt index f61deb4..d5d487d 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForView.kt @@ -79,16 +79,19 @@ class ScreenshotScenarioRuleForView( } override fun waitForMeasuredView(actionToDo: () -> View): View { + screenshotRule.withScenario(activityScenarioRule.activityScenario) viewToScreenshot = androidUiTestingUtilsMeasuredView { actionToDo() } return androidUiTestingUtilsMeasuredView { actionToDo() } } override fun waitForMeasuredDialog(actionToDo: () -> Dialog): Dialog { + screenshotRule.withScenario(activityScenarioRule.activityScenario) viewToScreenshot = androidUiTestingUtilsMeasuredView { actionToDo().window!!.decorView } return androidUiTestingUtilsMeasuredDialog { actionToDo() } } override fun waitForMeasuredViewHolder(actionToDo: () -> RecyclerView.ViewHolder): RecyclerView.ViewHolder { + screenshotRule.withScenario(activityScenarioRule.activityScenario) viewToScreenshot = androidUiTestingUtilsMeasuredView { actionToDo().itemView } return androidUiTestingUtilsMeasuredViewHolder { actionToDo() } } From 3e8cc5f6e3f43d5d850c49af3f167124ac00df6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Sun, 8 Sep 2024 09:18:37 +0200 Subject: [PATCH 4/7] Upgrade Robolectric to 4.13 internally --- gradle.properties | 2 +- robolectric/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5de474e..5ea4cf1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true -android.jetifier.ignorelist=android-base-common,common +android.jetifier.ignorelist=android-base-common,common,bcprov # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official android.defaults.buildfeatures.buildconfig=true diff --git a/robolectric/build.gradle b/robolectric/build.gradle index 8764726..990e75a 100644 --- a/robolectric/build.gradle +++ b/robolectric/build.gradle @@ -41,7 +41,7 @@ android { dependencies { implementation project(':utils') - implementation "org.robolectric:robolectric:4.12.1" + implementation "org.robolectric:robolectric:4.13" } //https://www.talentica.com/blogs/publish-your-android-library-on-jitpack-for-better-reachability/ From ee34d88beee84b3e25b51bb432f5aeebdd45bb73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Wed, 11 Sep 2024 14:40:01 +0200 Subject: [PATCH 5/7] Set AndroidTestifyConfig default useSoftwareRenderer = false like in android-testify --- .../android_testify/AndroidTestifyConfig.kt | 2 +- .../ScreenshotScenarioRuleExt.kt | 6 ----- .../ScreenshotScenarioRuleForComposable.kt | 22 +++++-------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt index 5fa7a23..c97f6a2 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/AndroidTestifyConfig.kt @@ -19,7 +19,7 @@ class AndroidTestifyConfig( val hideScrollbars: Boolean = true, val hideSoftKeyboard: Boolean = true, val hideTextSuggestions: Boolean = true, - val useSoftwareRenderer: Boolean = true, + val useSoftwareRenderer: Boolean = false, val exclusionRects: MutableSet = HashSet(), val exclusionRectProvider: ExclusionRectProvider? = null, val compareMethod: CompareMethod? = null, diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt index 39c2e6a..4cb696d 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleExt.kt @@ -56,12 +56,6 @@ internal fun ScreenshotScenarioRule.setViewUnderTest( } } -internal fun ScreenshotScenarioRule.setComposeViewUnderTest( - view: View, -): ScreenshotScenarioRule = apply { - setScreenshotViewProvider { view } -} - internal fun ScreenshotScenarioRule.setBitmapCaptureMethod( bitmapCaptureMethod: BitmapCaptureMethod?, ): ScreenshotScenarioRule = apply { diff --git a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt index dffa854..bf9d11f 100644 --- a/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt +++ b/android-testify/src/main/java/sergio/sastre/uitesting/android_testify/screenshotscenario/ScreenshotScenarioRuleForComposable.kt @@ -65,14 +65,9 @@ class ScreenshotScenarioRuleForComposable( override fun snapshot(composable: @Composable () -> Unit) { screenshotRule .withScenario(activityScenarioRule.activityScenario) - - val composeView = - activityScenarioRule - .setContent(composable) - .composeView - - screenshotRule - .setComposeViewUnderTest(composeView) + .setScreenshotViewProvider { + activityScenarioRule.setContent { composable() }.composeView + } .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) .generateDiffs(androidTestifyConfig.generateDiffs) .assertSame(null) @@ -81,14 +76,9 @@ class ScreenshotScenarioRuleForComposable( override fun snapshot(name: String?, composable: @Composable () -> Unit) { screenshotRule .withScenario(activityScenarioRule.activityScenario) - - val composeView = - activityScenarioRule - .setContent(composable) - .composeView - - screenshotRule - .setComposeViewUnderTest(composeView) + .setScreenshotViewProvider { + activityScenarioRule.setContent { composable() }.composeView + } .setBitmapCaptureMethod(androidTestifyConfig.bitmapCaptureMethod) .generateDiffs(androidTestifyConfig.generateDiffs) .assertSame(name = name) From 49d0a2ce7022e718e8a3b11c1a5b15a70594f917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Wed, 11 Sep 2024 18:17:03 +0200 Subject: [PATCH 6/7] Dependency updates --- android-testify/build.gradle | 7 +++++-- dropshots/build.gradle | 7 +++++-- roborazzi/build.gradle | 2 +- shot/build.gradle | 2 +- utils/build.gradle | 12 +++++------- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/android-testify/build.gradle b/android-testify/build.gradle index df7fdc8..ddea2b6 100644 --- a/android-testify/build.gradle +++ b/android-testify/build.gradle @@ -51,9 +51,12 @@ android { dependencies { implementation project(':utils') - implementation 'androidx.test:rules:1.5.0' + //noinspection GradleDependency + implementation ('androidx.test:rules:1.5.0') { + because "1.6.x makes tests fail when running Gradle Managed Devices" + } api 'dev.testify:testify:3.2.0' - api 'androidx.activity:activity-compose:1.8.2' + api 'androidx.activity:activity-compose:1.9.2' } //https://www.talentica.com/blogs/publish-your-android-library-on-jitpack-for-better-reachability/ diff --git a/dropshots/build.gradle b/dropshots/build.gradle index 0cceb2d..7331f70 100644 --- a/dropshots/build.gradle +++ b/dropshots/build.gradle @@ -50,9 +50,12 @@ android { dependencies { implementation project(':utils') - implementation 'androidx.test:rules:1.5.0' + //noinspection GradleDependency + implementation ('androidx.test:rules:1.5.0') { + because "1.6.x makes tests fail when running Gradle Managed Devices" + } api 'com.dropbox.dropshots:dropshots:0.4.1' - api 'androidx.activity:activity-compose:1.8.2' + api 'androidx.activity:activity-compose:1.9.2' } //https://www.talentica.com/blogs/publish-your-android-library-on-jitpack-for-better-reachability/ diff --git a/roborazzi/build.gradle b/roborazzi/build.gradle index f27bece..577bf40 100644 --- a/roborazzi/build.gradle +++ b/roborazzi/build.gradle @@ -55,7 +55,7 @@ dependencies { api 'androidx.test.espresso:espresso-core:3.5.1' api 'org.hamcrest:hamcrest:2.2' - api 'androidx.activity:activity-compose:1.8.2' + api 'androidx.activity:activity-compose:1.9.2' } //https://www.talentica.com/blogs/publish-your-android-library-on-jitpack-for-better-reachability/ diff --git a/shot/build.gradle b/shot/build.gradle index ba6bb46..adb37e5 100644 --- a/shot/build.gradle +++ b/shot/build.gradle @@ -51,7 +51,7 @@ android { dependencies { implementation project(':utils') api 'com.karumi:shot-android:6.1.0' - api 'androidx.activity:activity-compose:1.8.2' + api 'androidx.activity:activity-compose:1.9.2' implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3' } diff --git a/utils/build.gradle b/utils/build.gradle index 1b0040f..5fabc1e 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -55,15 +55,13 @@ dependencies { api 'androidx.appcompat:appcompat:1.7.0' api 'com.google.android.material:material:1.12.0' api 'androidx.test:core:1.6.1' - //noinspection GradleDependency - api ('androidx.core:core-ktx:1.9.0') { - because '1.10.0 caused troubles with Paparazzi in the past' + api ('androidx.test.espresso:espresso-core:3.5.1') { + because "3.6.x makes tests fail when running Gradle Managed Devices" } - api 'androidx.test.ext:junit:1.1.5' - api 'androidx.test.espresso:espresso-core:3.5.1' - api 'androidx.compose.ui:ui-test-junit4:1.5.4' - api 'androidx.fragment:fragment-ktx:1.6.2' + api 'androidx.compose.ui:ui-test-junit4:1.7.1' + api 'androidx.fragment:fragment-ktx:1.8.3' + implementation 'androidx.core:core-ktx:1.13.1' implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3' } From a548cae9232b2da6af13bb99a4b3e0ae31cf21a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Sastre=20Fl=C3=B3rez?= Date: Wed, 11 Sep 2024 18:24:10 +0200 Subject: [PATCH 7/7] Update modules to 2.4.0 --- android-testify/build.gradle | 2 +- dropshots/build.gradle | 2 +- mapper-paparazzi/build.gradle | 2 +- mapper-roborazzi/build.gradle | 2 +- paparazzi/build.gradle | 2 +- robolectric/build.gradle | 2 +- roborazzi/build.gradle | 2 +- shot/build.gradle | 2 +- utils/build.gradle | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/android-testify/build.gradle b/android-testify/build.gradle index ddea2b6..f8bda61 100644 --- a/android-testify/build.gradle +++ b/android-testify/build.gradle @@ -65,7 +65,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "android-testify" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/dropshots/build.gradle b/dropshots/build.gradle index 7331f70..39aa21e 100644 --- a/dropshots/build.gradle +++ b/dropshots/build.gradle @@ -64,7 +64,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "dropshots" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/mapper-paparazzi/build.gradle b/mapper-paparazzi/build.gradle index 995588f..660f36d 100644 --- a/mapper-paparazzi/build.gradle +++ b/mapper-paparazzi/build.gradle @@ -49,7 +49,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "mapper-paparazzi" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/mapper-roborazzi/build.gradle b/mapper-roborazzi/build.gradle index be1f4a6..e698a19 100644 --- a/mapper-roborazzi/build.gradle +++ b/mapper-roborazzi/build.gradle @@ -50,7 +50,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "mapper-roborazzi" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/paparazzi/build.gradle b/paparazzi/build.gradle index 686b298..735cf83 100644 --- a/paparazzi/build.gradle +++ b/paparazzi/build.gradle @@ -57,7 +57,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "paparazzi" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/robolectric/build.gradle b/robolectric/build.gradle index 990e75a..171f4cf 100644 --- a/robolectric/build.gradle +++ b/robolectric/build.gradle @@ -50,7 +50,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "robolectric" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/roborazzi/build.gradle b/roborazzi/build.gradle index 577bf40..a72bdef 100644 --- a/roborazzi/build.gradle +++ b/roborazzi/build.gradle @@ -64,7 +64,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "roborazzi" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/shot/build.gradle b/shot/build.gradle index adb37e5..b309815 100644 --- a/shot/build.gradle +++ b/shot/build.gradle @@ -61,7 +61,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "shot" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release diff --git a/utils/build.gradle b/utils/build.gradle index 5fabc1e..71ea107 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -71,7 +71,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.sergio-sastre' artifactId = "utils" - version = '2.3.5' + version = '2.4.0' afterEvaluate { from components.release