I am working with Nexus 5 and Cyanogen One plus devices with Lollipop android OS. I am trying to test various notifications of certain app. I was successfully able to test tray notification and lock screen notification with UiAutomator but I am not able to have any success with headsup notification. I tried following code but it failed to detect it.
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());
}
Is there a way to detect headsup notifications in UiAutomator as an object to look for when running automation?
A notification is a message that Android displays outside your app's UI to provide the user with reminders, communication from other people, or other timely information from your app. Users can tap the notification to open your app or take an action directly from the notification.
Users typically see a notification as a banner or pop-up alert as they use their phone. The alert appears no matter what the user is doing. Most mobile operating systems also show push notifications together in a single view. On iOS, Apple has a Notification Center.
Custom Notifications option lets you select tones, vibration length, light, popup notifications, call ringtone, among others.
@Before
public void setUp() throws Exception
{
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
}
@Test
public 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")
.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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With