uiAutomator里面有这个几个类: UiDevice UiSelect UiObject
在stackoverflow上面有一个回答是通过获取到通知栏的UiObject对象来做处理的,代码如下
Selector 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());
但是这应该是通知栏打开之后的操作了,那么怎么打开通知栏呢,代码如下
/**
* 通过手势操作打开通知栏
* @throws UiObjectNotFoundException
*/
public void testViewNotification() throws UiObjectNotFoundException{
device.pressHome();
device.swipe(300, 0, 300, 800, 50);
device.waitForIdle(2000);
device.pressBack();
}
通过UiDevice中的swipe方法,模拟滑动操作,从状态栏上面下滑, 方法是UiDevice.swipe(startX,startY,endX,endY,steps)