kvh*_*kvh 5 android android-testing android-espresso android-uiautomator
我向WindowManager添加了一个浮动视图,并使其可以在屏幕上移动,我可以在单击此视图时执行单击事件,一切正常.
但是,我不知道如何在espresso或UIAutomator中访问此视图.
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);
Run Code Online (Sandbox Code Playgroud)
rect中的白蓝色图标是我正在谈论的浮动视图.
浮动视图响应单击事件,并执行一些任务,现在我想在AndroidJunit测试中执行此操作.
我使用onView方法尝试Espresso,但测试用例:
onView(withContentDescription("bugtags_fab_des_normal")).perform(click());
Run Code Online (Sandbox Code Playgroud)
得到:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with content description: is "bugtags_fab_des_normal"
Run Code Online (Sandbox Code Playgroud)
我尝试UIAutomator Viewer,但我在视图层次结构中找不到floatingView.
如何在espresso或uiautomator中访问此视图并执行单击操作?
@Test
public void testInvoke() {
onView(withContentDescription("bugtags_fab_des_normal")).perform(click());
}
Run Code Online (Sandbox Code Playgroud)
实际上,我使用的是一个名为bugtags.com的sdk ,它是一个简单的app bug报告和崩溃分析工具.
你的观点在外面,Activity所以可以通过使用inRoot()方法找到它:
@Test
public void checkClickOnFloatingButton() {
onView(withContentDescription("bugtags_fab_des_normal")).inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView())))).perform(click());
}
Run Code Online (Sandbox Code Playgroud)
还你应该改变reportImage,以floatingView在这段代码:
ImageView floatingView = new ImageView(mContext);
reportImage.setContentDescription("bugtags_fab_des_normal"); // <---`reportImage` to `floatingView`
mWindowManager.addView(floatingView, layoutParams);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1046 次 |
| 最近记录: |