📸
AndroidUiTestingUtils
  • Overview
  • Setup
    • Instrumentation setup
    • Robolectric setup
    • Cross-Library setup
  • Usage
    • Instrumentation tests usage
      • Android-Testify usage
    • Robolectric usage
    • Cross-Library usage
    • TestRules & other utils
  • Ready-to-Run Samples
  • Github
Powered by GitBook
On this page
  • TestRules
  • WaitFor...
  • Inflate or measure
  1. Usage

TestRules & other utils

Some utilities and TestRules to facilitate UI and Screenshot Testing

TestRules

@get:Rule
val disableAnimations = DisableAnimationsTestRule()

// Sets the Locale of the app under test only, i.e. the per-app language preference feature
@get:Rule
val inAppLocale = InAppLocaleTestRule("en")

// Sets the Locale of the Android system
@get:Rule
val systemLocale = SystemLocaleTestRule("en")

@get:Rule
val fontSize = FontSizeTestRule(FontSize.LARGEST)

@get:Rule
val displaySize = DisplaySizeTestRule(DisplaySize.LARGEST)

@get:Rule
val uiMode = UiModeTestRule(UiMode.NIGHT)

WaitFor...

  1. waitForFragment Analogue to waitForActivity but for Fragment.

  2. activity.waitForComposeView Returns the root Composable in the activity as a ComposeView. You can call later drawToBitmap or drawToBitmapWithElevation on it to screenshot test its corresponding bitmap.

  3. waitForMeasuredView/Dialog/ViewHolder(exactWidth, exactHeight) Inflates the layout in the main thread, sets its width and height to those given, and waits till the thread is idle, returning the inflated view. Comes in handy with libraries that do not support to take a screenshot with a given width/height, like Dropshots.

Prefer waitForMeasuredView over waitForView (which is discouraged), specially if using Dropshots

Inflate or measure

  1. activity.inflate(R.layout_of_your_view) Use it to inflate android Views with the activity's context configuration. In doing so, the configuration becomes effective in the view. It also adds the view to the Activity's root.

  2. activity.inflateAndWaitForIdle(R.layout_of_your_view) Like activity.inflate(...), but waits till the view is Idle to return it

Do not wrap it with waitForMeasuredView{...} or it will throw an exception.

PreviousCross-Library usageNextReady-to-Run Samples

Last updated 1 year ago

waitForActivity Analogue to the one defined in . It's also available in this library for compatibility with other screenshot testing frameworks, like Facebook .

Difference between waitForView() and waitForMeasuredView()

MeasureViewHelpers Analogue to the ViewHelpers defined in Facebook . In most cases, you don't need to use it directly but via waitForMeasuredView(exactWidth, exactHeight), which calls MeasuredViewHelpers under the hood.

pedrovgs/Shot
screenshot-tests-for-android
screenshot-tests-for-android