Class ComposableScreenshotRule
-
- All Implemented Interfaces:
-
dev.testify.CompatibilityMethods,dev.testify.ScreenshotLifecycle,dev.testify.core.logic.AssertionState,dev.testify.core.logic.ScreenshotLifecycleHost,dev.testify.internal.helpers.ActivityProvider,org.junit.rules.TestRule
public class ComposableScreenshotRule extends ScreenshotRule<ComposableTestActivity>
Helper extension of ScreenshotRule which simplifies testing Composable functions.
-
-
Field Summary
Fields Modifier and Type Field Description private Function0<Unit>composeFunctionprivate final Instrumentation.ActivityResultactivityResultprivate BooleanassertSameInvokedprivate BooleanisDebugModeprivate IntegerrootViewIdprivate Function1<ViewGroup, View>screenshotViewProviderprivate IntegertargetLayoutIdprivate Throwablethrowableprivate Function1<ViewGroup, Unit>viewModification
-
Constructor Summary
Constructors Constructor Description ComposableScreenshotRule(Float exactness, Boolean enableReporter, ComposeTestRule composeTestRule)
-
Method Summary
Modifier and Type Method Description final Function0<Unit>getComposeFunction()final UnitsetComposeFunction(Function0<Unit> composeFunction)UnitonCleanUp(Activity activity)ComposableScreenshotRulesetCaptureMethod(Function2<Activity, View, Bitmap> captureMethod)UnitbeforeAssertSame()Set a screenshot view provider to capture only the @Composable bounds UnitafterScreenshot(Activity activity, Bitmap currentBitmap)Proactively dispose of any compositions after the screenshot has been taken. final ComposableScreenshotRulesetCompose(Function0<Unit> composable)Used to provide a @Composable function to be rendered in the screenshot. final ComposableScreenshotRulesetComposeActions(Function1<ComposeTestRule, Unit> actions)UI tests in Compose use semantics to interact with the UI hierarchy. UnitafterInitializeView(Activity activity)Test lifecycle method. UnitbeforeScreenshot(Activity activity)Test lifecycle method. Statementapply(Statement base, Description description)Modifies the method-running Statement to implement this test-running rule. ComposableScreenshotRuleconfigure(Function1<TestifyConfiguration, Unit> configureRule)Set the configuration for the ComposableScreenshotRule -
Methods inherited from class androidx.test.rule.ActivityTestRule
finishActivity, getActivity, getActivityResult, runOnUiThread -
Methods inherited from class dev.testify.ScreenshotRule
addIntentExtras, apply, assertForScreenshotInstrumentationAnnotation, assertSame, assureActivity, getActivityIntent, getAssertSameInvoked, getRootViewId, getScreenshotViewProvider, getTargetLayoutId, getThrowable, getViewModification, isDebugMode, launchActivity, setAssertSameInvoked, setDebugMode, setEspressoActions, setRootViewId, setRootViewId, setScreenshotViewProvider, setScreenshotViewProvider, setTargetLayoutId, setTargetLayoutId, setThrowable, setViewModification, setViewModifications, withExperimentalFeatureEnabled -
Methods inherited from class dev.testify.core.logic.ScreenshotLifecycleHost
addScreenshotObserver, notifyObservers, removeScreenshotObserver -
Methods inherited from class dev.testify.ScreenshotLifecycle
applyConfiguration, beforeInitializeView -
Methods inherited from class dev.testify.CompatibilityMethods
defineExclusionRects, setCompareMethod, setExactness, setFocusTarget, setFontScale, setHideCursor, setHidePasswords, setHideScrollbars, setHideSoftKeyboard, setHideTextSuggestions, setLayoutInspectionModeEnabled, setLocale, setOrientation, setRecordModeEnabled, setUseSoftwareRenderer, withRule -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ComposableScreenshotRule
ComposableScreenshotRule(Float exactness, Boolean enableReporter, ComposeTestRule composeTestRule)
- Parameters:
exactness- : The tolerance used when comparing the current image to the baseline.enableReporter- Whether the reporter is run for this test rule.composeTestRule- : A TestRule that allows you to test and control composables and applications using Compose.
-
-
Method Detail
-
getComposeFunction
final Function0<Unit> getComposeFunction()
-
setComposeFunction
final Unit setComposeFunction(Function0<Unit> composeFunction)
-
setCaptureMethod
@Deprecated(message = "Please use configure()", replaceWith = @ReplaceWith(imports = {}, expression = "configure { this@configure.captureMethod = captureMethod }")) ComposableScreenshotRule setCaptureMethod(Function2<Activity, View, Bitmap> captureMethod)
-
beforeAssertSame
Unit beforeAssertSame()
Set a screenshot view provider to capture only the @Composable bounds
-
afterScreenshot
Unit afterScreenshot(Activity activity, Bitmap currentBitmap)
Proactively dispose of any compositions after the screenshot has been taken.
-
setCompose
final ComposableScreenshotRule setCompose(Function0<Unit> composable)
Used to provide a @Composable function to be rendered in the screenshot.
-
setComposeActions
final ComposableScreenshotRule setComposeActions(Function1<ComposeTestRule, Unit> actions)
UI tests in Compose use semantics to interact with the UI hierarchy. setComposeActions allows you to manipulate your Compose UI using Finders and Actions.
The provided actions lambda will be invoked after the Activity is loaded, before any Espresso actions and before the screenshot is taken.
For more information:
- Parameters:
actions- : A lambda which provides a ComposeTestRule instance that can be used with semantics to interact with the UI hierarchy.
-
afterInitializeView
Unit afterInitializeView(Activity activity)
Test lifecycle method. Invoked after layout inflation and all view modifications have been applied.
-
beforeScreenshot
Unit beforeScreenshot(Activity activity)
Test lifecycle method. Invoked immediately before the screenshot is taken.
-
apply
Statement apply(Statement base, Description description)
Modifies the method-running Statement to implement this test-running rule.
-
configure
ComposableScreenshotRule configure(Function1<TestifyConfiguration, Unit> configureRule)
Set the configuration for the ComposableScreenshotRule
- Parameters:
configureRule-TestifyConfiguration
-
-
-
-