单击 espresso 中的 FloatingActionButton

Click on FloatingActionButton in espresso

尝试在 espresso 测试中点击 FloatingActionButton。

onView(withId(R.id.actionButton)).perform(customClick())

我的方法 customClick:

fun customClick(): ViewAction {
    return actionWithAssertions(
            CustomGeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER))
}

同时创建 class CustomGeneralClickAction 并进行一些更改:

Matcher<View> standardConstraint = isDisplayingAtLeast(60);

这个例子是我从这个 answer 中得到的。 但是有下一个错误:

android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: com.fentury.android:id/actionButton'.

Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'.

还有这里:

at com.fentury.android.acceptanceTests.utils.CustomGeneralClickAction.perform(CustomGeneralClickAction.java:79)

status = tapper.sendTap(uiController, coordinates, precision);

应该是onView(withId(R.id.floating_action_button)).perform(click());