Having a TextView with text value filled out and height set to WRAP_CONTENT
Then Espresso doesn't find a TextView claiming it's height is 0.
Important: Setting a padding or fixed height fixes the problem.
androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "AppCompatTextView{id=2131230876, res-name=intro_register, visibility=VISIBLE, width=320, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@1b791dca, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=50.0, text=Register, input-type=0, ime-target=false, has-links=false}"
I have a very simple layout in a fragment: FrameLayout with LinearLayout inside with 2 TextViews:
https://paste.ofcode.org/45iw4Ww6mBhtx576h7y5xk
My TextView has a height= "wrap_content" (no padding - important) and text value "Register"
`
<data>
<import type="android.view.View" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".intro.ui.IntroFragment"
android:id="@+id/intro_screen">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="I AR BLANK!"
android:textColor="#f00" />
<LinearLayout
android:id="@+id/intro_login_options"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="bottom"
android:alpha="0"
android:background="#b2b2b2"
android:elevation="3dp"
android:orientation="vertical"
android:paddingTop="50dp"
android:visibility="gone"
tools:alpha="1"
tools:visibility="visible">
<TextView
android:id="@+id/intro_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/register_button_label" />
<TextView
android:id="@+id/intro_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/login_button_label" />
</LinearLayout>
</FrameLayout>
`
And a basic test:
https://paste.ofcode.org/9VhYxDNSYgVNETZ6DnZhVZ
`
@RunWith(AndroidJUnit4::class)
class IntroActivityTest {
@get:Rule
val rule = ActivityTestRule(IntroActivity::class.java, false, false)
@Test
fun `Registration flow`() {
rule.launchActivity(null)
onView(withId(R.id.intro_register)).check(matches(isDisplayed()))
}
}`
Robolectric : 4.1
Android:
compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28
Databinding: enabled.
Codebase: Kotlin
Thanks for the report. I suspect this is related to #4153 but we'll take a closer look to confirm
I was having the same problem on a EditText.
Digging a bit i've discovered that, even thought both width and height were set as WRAP_CONTENT, the actual width value was 0 while the height value was 48dp
After some tests removing a few properties from my EditText, i've noticed that the issue was related to the ems property from EditText.
Removing that property fixed the problem (at least in this case)
I don't know but maybe this info can be useful on solving this
Can you try on 4.3-alpha-2 with @LooperMode(PAUSED) + @TextLayoutMode(REALISTIC) and let us know if that fixes your issue? Please reopen if not.
i still got the same result :
Expected :is displayed on the screen to the user
Actual :"AppCompatButton{id=2131296398, res-name=btn_soft_register, visibility=VISIBLE, width=328, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.support.constraint.ConstraintLayout$LayoutParams@5bd35a2e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=-2.0, y=505.0, text=SET UP YOUR EMAIL, input-type=0, ime-target=false, has-links=false}"
Most helpful comment
i still got the same result :
Expected :is displayed on the screen to the user
Actual :"AppCompatButton{id=2131296398, res-name=btn_soft_register, visibility=VISIBLE, width=328, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.support.constraint.ConstraintLayout$LayoutParams@5bd35a2e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=-2.0, y=505.0, text=SET UP YOUR EMAIL, input-type=0, ime-target=false, has-links=false}"