facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

All TextViews are not wrapping #243

Closed davidvavra closed 4 years ago

davidvavra commented 4 years ago

Hi, I'm trying to use this library. I'm testing a custom view which contains a bunch of TextViews. I'm creating the custom view via constructor with Context. Then I'm testing it with:

ViewHelpers.setupView(view).setExactWidthDp(300).layout()
Screenshot.snap(view).record()

All textViews are cut to one line at that 300dp, they don't wrap. In the app it does wrap.

Any idea in which way to investigate?

davidvavra commented 4 years ago

So I found a root cause - data binding.

After binding data to a View, I need to call this code:

private fun <T : View> T.executePendingBindings() {
        val binding = DataBindingUtil.getBinding<ViewDataBinding>(this)
        binding?.executePendingBindings()
        if (this is ViewGroup) {
            children.forEach {
                it.executePendingBindings()
            }
        }
    }

plus data binding requires that this runs on Main thread, not test thread. Afterwards, the layout is fine.

xiphirx commented 4 years ago

Closing as this is due to extra setup needed for databinding. Unsure if that can be baked into the library.