TestRules & other utils
Some utilities and TestRules to facilitate UI and Screenshot Testing
TestRules
WaitFor...
waitForActivity
Analogue to the one defined in pedrovgs/Shot. It's also available in this library for compatibility with other screenshot testing frameworks, like Facebook screenshot-tests-for-android.waitForFragment
Analogue towaitForActivity
but for Fragment.activity.waitForComposeView
Returns the root Composable in the activity as a ComposeView. You can call laterdrawToBitmap
ordrawToBitmapWithElevation
on it to screenshot test its corresponding bitmap.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
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.activity.inflateAndWaitForIdle(R.layout_of_your_view)
Likeactivity.inflate(...)
, but waits till the view is Idle to return it
Do not wrap it with waitForMeasuredView{...}
or it will throw an exception.
MeasureViewHelpers
Analogue to theViewHelpers
defined in Facebook screenshot-tests-for-android. In most cases, you don't need to use it directly but viawaitForMeasuredView(exactWidth, exactHeight)
, which callsMeasuredViewHelpers
under the hood.
Last updated