-
- All Implemented Interfaces:
-
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 Floatexactnessprivate final WeakReference<ComposableTestActivity>activityprivate final IntegerdeviceOrientationprivate final StringfullyQualifiedTestPathprivate BooleanisDebugModeprivate final BooleanoutputFileExistsprivate StringtestMethodNameprivate final StringtestNameprivate final Pair<String, String>testNameComponents
-
Constructor Summary
Constructors Constructor Description ComposableScreenshotRule(Float exactness, ComposeTestRule composeTestRule)
-
Method Summary
Modifier and Type Method Description final Function0<Unit>getComposeFunction()final UnitsetComposeFunction(Function0<Unit> composeFunction)final FloatgetExactness()final UnitsetExactness(Float exactness)final IntegergetDeviceOrientation()final StringgetFullyQualifiedTestPath()final BooleangetIsDebugMode()final UnitsetIsDebugMode(Boolean isDebugMode)final BooleangetOutputFileExists()StringgetTestMethodName()UnitsetTestMethodName(String testMethodName)final StringgetTestName()final Pair<String, String>getTestNameComponents()UnitonCleanUp(Activity activity)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. -
Methods inherited from class dev.testify.ComposableScreenshotRule
addIntentExtras, applyViewModifications, assertSame, beforeInitializeView, defineExclusionRects, getExactness, getModuleName, getRootView, instrumentationPrintln, isRecordMode, launchActivity, setEspressoActions, setExactness, setFocusTarget, setFontScale, setHideCursor, setHidePasswords, setHideScrollbars, setHideSoftKeyboard, setHideTextSuggestions, setLayoutInspectionModeEnabled, setLocale, setOrientation, setRootViewId, setScreenshotViewProvider, setTargetLayoutId, setUseSoftwareRenderer, setViewModifications, withExperimentalFeatureEnabled -
Methods inherited from class dev.testify.ScreenshotRule
afterActivityFinished, callFinishOnMainSync, finishActivity, getActivity, getActivityResult, makeWeakReference, runOnUiThread, setInstrumentation -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ComposableScreenshotRule
ComposableScreenshotRule(Float exactness, ComposeTestRule composeTestRule)
- Parameters:
exactness- : The tolerance used when comparing the current image to the baseline.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)
-
getExactness
final Float getExactness()
-
setExactness
final Unit setExactness(Float exactness)
- Parameters:
exactness- : The tolerance used when comparing the current image to the baseline.
-
getDeviceOrientation
final Integer getDeviceOrientation()
-
getFullyQualifiedTestPath
final String getFullyQualifiedTestPath()
-
getIsDebugMode
final Boolean getIsDebugMode()
-
setIsDebugMode
final Unit setIsDebugMode(Boolean isDebugMode)
-
getOutputFileExists
final Boolean getOutputFileExists()
-
getTestMethodName
String getTestMethodName()
-
setTestMethodName
Unit setTestMethodName(String testMethodName)
-
getTestName
final String getTestName()
-
getTestNameComponents
final Pair<String, String> getTestNameComponents()
-
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.
-
-
-
-