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

Screenshot testing does not support xml files that use Kotlin data binding #244

Closed ddeleon92 closed 4 years ago

ddeleon92 commented 4 years ago

This 1 is more of a question that could lead to an issue/enhancement.

I'm currently implementing testing across multiple projects at work but have hit a snag. Writing test for layout that use data binding return blank screens. Using this format....

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
        <variable
            name="viewModel"
            type="com.example.MyViewModel" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

I am constantly returned an empty view. When I remove "layout" and "data" just leaving the ConstraintLayout by itself, the views show with no problem. No error message reported. The app itself runs fine on devices with the data binding enabled so I know my seniors code being written wrong isn't the issue.

So my question is: Do the screenshot test support layouts that use data binding?

xiphirx commented 4 years ago

You will need ensure the view is created properly through whatever pipeline Data Binding requires. The library itself doesn't instantiate the view for you, it just captures a screenshot of the view you give it.

ddeleon92 commented 4 years ago

to get rootView out

ViewHolder(DataBindingUtil.inflate<ListItemBinding>(inflater, "layout here", null, false).apply {
                                executePendingBindings()
                            }.root)