FloatingActionButton icon indicating copy to clipboard operation
FloatingActionButton copied to clipboard

How to perform click operation using Google Expresso UI Testing framework

Open tarkikmittal opened this issue 9 years ago • 3 comments

I am writing a UI automation test case using Google Expresso UI testing framework. I have added id and contentDescription to but still not able to perform click on floating button.

my code as below

layout.xml <com.github.clans.fab.FloatingActionMenu android:id="@+id/fltBtn" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" fab:menu_animationDelayPerItem="20" android:contentDescription="@string/floating_button" fab:menu_backgroundColor="#bbcccccc" />

test.java

onView(withId(R.id.fltBtn)).check(matches(isDisplayed())); onView(withId(R.id.fltBtn)).perform(click());

onView(withContentDescription(R.string.floating_button)).perform(click());

both commands are not working. can you please suggest what will enable UI testing of these components. as same is working in default floating button provided by android

tarkikmittal avatar Apr 19 '16 11:04 tarkikmittal

I just had the same issue. I was able to resolve it using this matcher:

onView(allOf(withParent(withId(R.id.fab)), withClassName(endsWith("ImageView")), isDisplayed()))
.perform(click());

The Problem is that the FloatingActionMenu is a ViewGroup which is inflating the FloatingActionButton as child of the view with the fab id.

DreierF avatar Jul 07 '16 12:07 DreierF

Thanks @DreierF. I'm using that as well and it works great.

jacobras avatar Nov 30 '16 18:11 jacobras

I'm using this third party floating action button "com.github.ag.floatingactionmenu.OptionsFabLayout". In this case, how can i click on the floating action button ?

kpradeepkumarreddy avatar Aug 30 '18 14:08 kpradeepkumarreddy