【发布时间】:2023-03-21 15:52:02
【问题描述】:
我在 WindowManager 中添加了一个浮动视图,并让它在屏幕上移动,当我点击这个视图时我可以执行点击事件,一切正常。
但是,我不知道如何在 espresso 或 UIAutomator 中访问此视图。
将视图添加到 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);
浮动视图
矩形中的白蓝图标是我所说的浮动视图。
问题
浮动视图响应点击事件,并执行一些任务,现在我想在 AndroidJunit 测试中执行此操作。
- 浓缩咖啡
我尝试 Espresso,使用 onView 方法,但测试用例:
onView(withContentDescription("bugtags_fab_des_normal")).perform(click());
获取:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with content description: is "bugtags_fab_des_normal"
- UIAutomator
我尝试使用 UIAutomator Viewer,但在视图层次结构中找不到 floatingView。
如何
我如何在 espresso 或 uiautomator 中访问此视图并单击它?
附录
测试用例
@Test
public void testInvoke() {
onView(withContentDescription("bugtags_fab_des_normal")).perform(click());
}
输出日志
Bugtags.com
实际上,我正在使用一个名为bugtags.com 的sdk,它是一个用于应用程序错误报告和崩溃分析的简单工具。
【问题讨论】:
-
能否提供完整的 android.support.test.espresso.NoMatchingViewException 日志:
-
嗨,我已经附加了测试用例和输出日志。
-
嘿嘿!你是如何实现那个浮动按钮并处理它的点击事件的?请提供它的代码或教程链接!
标签: android android-testing android-espresso android-uiautomator