Issue
I add a floating view to the WindowManager, and make it movable around the screen, and i can perform click event when i click this view, everything works fine.
However, I don't know how to access this view in espresso or UIAutomator.
Add view to WindowManager
final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
type,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT
);
ImageView floatingView = new ImageView(mContext);
floatingView.setContentDescription("bugtags_fab_des_normal");
mWindowManager.addView(floatingView, layoutParams);
The Floating View
the white-blue icon in rect is the floating view i am talking about.
Question
The floating view response a click event, and perform some task, now i want to do this in AndroidJunit test.
- Espresso
I try Espresso, using onView method, but the test case:
onView(withContentDescription("bugtags_fab_des_normal")).perform(click());
Get:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with content description: is "bugtags_fab_des_normal"
- UIAutomator
I try UIAutomator Viewer, but i can't find the floatingView in view hierarchy.
How
How can i access this view in espresso or uiautomator and perform click to it?
Appendix
Test Case
@Test
public void testInvoke() {
onView(withContentDescription("bugtags_fab_des_normal")).perform(click());
}
Output log
Bugtags.com
Actually, i am using a sdk called bugtags.com, it's a simple tool for app bug reporting and crash analysis.
Solution
Your view is outside of Activity so can find it by using inRoot() method:
@Test
public void checkClickOnFloatingButton() {
onView(withContentDescription("bugtags_fab_des_normal")).inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView())))).perform(click());
}
Also you probably should change reportImage to floatingView in this piece of code:
ImageView floatingView = new ImageView(mContext);
reportImage.setContentDescription("bugtags_fab_des_normal"); // <---`reportImage` to `floatingView`
mWindowManager.addView(floatingView, layoutParams);
Answered By - Ilya Tretyakov

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.