mardi 28 août 2018

Espresso test takes forever when ImageView is rotated

I have two similar ImageViews. I decided to not create different drawables for the second ImageView and rotate it using the same drawables.

<ImageView
    android:id="@+id/rightTurn_imageView"
    android:layout_width="@dimen/width_imageViews_feedback_area_info"
    android:layout_height="@dimen/height_imageViews_feedback_area_info"
    android:layout_marginLeft="@dimen/margin_before_imageViews_feedback_area_info"
    android:layout_marginStart="@dimen/margin_before_imageViews_feedback_area_info"
    android:layout_marginTop="@dimen/margin_above_imageViews_feedback_area_info"
    android:scaleType="fitCenter"
    app:layout_constraintStart_toEndOf="@+id/emergency_imageView"
    app:layout_constraintTop_toTopOf="@+id/feedback_area_info"
    android:rotation="180"/> <! -- The line where the problem occurs -->

I am trying to test my UI using Espresso. I am trying to see if a Toast appears and the Test function takes forever.

@Test
fun showToastOnClickRightDirectionLight() {
    onView(withId(R.id.rightTurn_imageView))
        .perform(click())
    onView(
        withText(
            containsString(
                activityRule.activity.resources.getString(
                    R.string.long_click_info
                )
            )
        )
    )
        .inRoot(RootMatchers.withDecorView(not(activityRule.activity.window.decorView)))
        .check(matches(isDisplayed()))
}

Whenever I remove the rotation line from xml (android:rotation="180") the test completes successfully. Is there any workaround for this problem, or should I create another drawable?

Also, can somebody explain why is this happening? What is wrong when rotating?

Aucun commentaire:

Enregistrer un commentaire