@foonfyrick

Espresso не получается протестировать floating action bar, почему выдает ошибку?

После нажатия на fab, она должна раскрыться и появиться еще одна кнопка, но ничего не происходит.
Вот ошибка: androidx.test.espresso.PerformException: Error performing 'single click' on view 'with id is example.app:id/menu_item_add
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
at least 90 percent of the view's area is displayed to the user.

@RunWith(AndroidJUnit4::class)
class EspressoTestMainFragment {
    @Rule
    fun rule():ActivityScenarioRule<MainActivity>
            = ActivityScenarioRule<MainActivity>(MainActivity::class.java)
//Тест: Показывается ли ресайклер вью при запуске
    @Test
    fun isRecyclerViewPnTheScreen(){
        Espresso
            .onView(ViewMatchers.withId(R.id.idrecyclerView))
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
    }
//Тест: проверка fab menu и fab menu_item_add
    @Test
    fun isFragmentMainFabWorking(){
        Espresso.onView(ViewMatchers.withId(R.id.menu)).perform(ViewActions.click())
        Espresso.onView(ViewMatchers.withId(R.id.menu_item_add)).perform(ViewActions.click())

    }

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.main.view.MainFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/idrecyclerView"
        android:layout_width="409dp"
        android:layout_height="729dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="24dp"
        android:layout_marginBottom="24dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        fab:menu_animationDelayPerItem="50"
        fab:menu_backgroundColor="@android:color/transparent"
        fab:menu_buttonSpacing="0dp"
        fab:menu_colorNormal="#DA4336"
        fab:menu_colorPressed="#E75043"
        fab:menu_colorRipple="#99FFFFFF"
        fab:menu_fab_label="закрыть"
        fab:menu_fab_size="normal"
        fab:menu_icon="@drawable/fab_add"
        fab:menu_labels_colorNormal="#333333"
        fab:menu_labels_colorPressed="#444444"
        fab:menu_labels_colorRipple="#66FFFFFF"
        fab:menu_labels_cornerRadius="3dp"
        fab:menu_labels_ellipsize="none"
        fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
        fab:menu_labels_margin="0dp"
        fab:menu_labels_maxLines="-1"
        fab:menu_labels_padding="8dp"
        fab:menu_labels_paddingBottom="4dp"
        fab:menu_labels_paddingLeft="8dp"
        fab:menu_labels_paddingRight="8dp"
        fab:menu_labels_paddingTop="4dp"
        fab:menu_labels_position="left"
        fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
        fab:menu_labels_showShadow="true"
        fab:menu_labels_singleLine="false"
        fab:menu_labels_textColor="#FFFFFF"
        fab:menu_labels_textSize="14sp"
        fab:menu_openDirection="up"
        fab:menu_shadowColor="#66000000"
        fab:menu_shadowRadius="4dp"
        fab:menu_shadowXOffset="1dp"
        fab:menu_shadowYOffset="3dp"
        fab:menu_showShadow="true">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/menu_item_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_float_add"
            fab:fab_label="добавить запись"
            fab:fab_size="mini" />


    </com.github.clans.fab.FloatingActionMenu>
</androidx.constraintlayout.widget.ConstraintLayout>
  • Вопрос задан
  • 169 просмотров
Решения вопроса 1
@foonfyrick Автор вопроса
onView(withId(R.id.menu_item_add)).check(
            matches(
                allOf(
                    isEnabled(),
                    isClickable()
                )
            )
        ).perform(
            object : ViewAction {
                override fun getDescription(): String {
                    return "click add button"
                }

                override fun getConstraints(): Matcher<View> {
                    return isEnabled()
                }

                override fun perform(uiController: UiController?, view: View?) {
                    view?.performClick()
                }
            }
        )
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы