public voID test_headsupTitle() throws InterruptedException,UiObjectNotFoundException,IOException{ //some code to bring up headsup notification UiObject maxheadsUp = new UiObject(new UiSelector().packagename("com.androID.systemUI").resourceID("androID:ID/status_bar_latest_event_content")); // code to add sleep so that it waits for heads up notification to show up assertTrue(maxheadsUp.exists());}
有没有办法在Uiautomator中检测抬头通知作为运行自动化时要查找的对象?
解决方法@Beforepublic voID setUp() throws Exception{ super.setUp(); injectInstrumentation(InstrumentationRegistry.getInstrumentation()); mDevice = UIDevice.getInstance(InstrumentationRegistry.getInstrumentation());}@Testpublic voID testNoti() throws UiObjectNotFoundException{ mDevice.openNotification(); mDevice.wait(Until.hasObject(By.pkg("com.androID.systemUI")),10000); /* * 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()); /* * access top notification in the center through parent */ UiObject notiSelectorUiObject = notificationStackScrollerUiObject.getChild(new UiSelector().index(0)); assertTrue(notiSelectorUiObject.exists()); notiSelectorUiObject.click();}总结
以上是内存溢出为你收集整理的android – 如何在uiautomator中检测抬头通知?全部内容,希望文章能够帮你解决android – 如何在uiautomator中检测抬头通知?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)