我是UI Automator的新手。我有一个作为服务运行的应用程序。它在通知栏上显示一个图标
有没有办法测试最近添加的通知栏顶部的图标?我在uiautomatorviewer中看不到任何控件
或者如果有从NotificationMgr API获取图标信息的方法,请让我知道,这将非常有帮助
我是UI Automator的新手。我有一个作为服务运行的应用程序。它在通知栏上显示一个图标
有没有办法测试最近添加的通知栏顶部的图标?我在uiautomatorviewer中看不到任何控件
或者如果有从NotificationMgr API获取图标信息的方法,请让我知道,这将非常有帮助
关于通知:
private UiObject getNotificationStackScroller()
{
/*
* access Notification Center through resource id, package name, class name.
* if you want to check resource id, package name or class name of the specific view in the screen,
* run 'uiautomatorviewer' from command.
*/
UiSelector notificationStackScroller = new UiSelector().packageName("com.android.systemui")
.className("android.view.ViewGroup")
.resourceId(
"com.android.systemui:id/notification_stack_scroller");
UiObject notificationStackScrollerUiObject = mDevice.findObject(notificationStackScroller);
assertTrue(notificationStackScrollerUiObject.exists());
return notificationStackScrollerUiObject;
}
并且可以通过以下方式访问任何“第i个”项:
UiObject notificationUiObject = getNotificationStackScroller().getChild(new UiSelector().index(i));
assertTrue(notificationUiObject.exists());
UiObject numberOfNotifications = notificationUiObject.getChild(new UiSelector().text("3"));
assertTrue(numberOfNotifications.exists());
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.mydomain.myuiautomatortests", appContext.getPackageName());
appContext.startActivity(new Intent(appContext, MainActivity.class));
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.openNotification();
}
}
Gradle Dependency
compile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' // or higher
下拉通知栏,然后检查状态栏中的项目。它们将在uiautomatorviewer中显示。