Clear Notifications


#1

Hi,

In Android appium, i know how to open the notifications screen (driver.openNotifications(); )

Is there is a way to clear all Notifications from screen ?

Thanks !


#2

@gilb i do it manually with:

    public void clearNotifications(AndroidDriver driver) {
        System.out.println("  clearNotifications()");
        driver.openNotifications();
        nativeNotificationPage = new NativeNotificationPage(driver);
        assertTrue("Native notification page is NOT loaded", nativeNotificationPage.isNativeNotificationPage());
        if (nativeNotificationPage.isClearAllBtnLoaded()) {
            nativeNotificationPage.tapClearAllBtn();
        } else {
            ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.BACK);
            sleep(1);
        }
        System.out.println("  notifications cleared");
    }

where Notification Page is (you can take all locators or use it as is):

public class NativeNotificationPage extends Page {

    @AndroidFindBy(id= "com.android.systemui:id/notification_panel")
    private List<AndroidElement> notificationPanel;
    //settings data
    @HowToUseLocators(androidAutomation = LocatorGroupStrategy.ALL_POSSIBLE)
    @AndroidFindBy(id = "com.android.systemui:id/clear_all_button")
    @AndroidFindBy(id = "com.android.systemui:id/dismiss_text")
    private List<AndroidElement> clearAllBtn;


    public NativeNotificationPage(WebDriver driver) {
        super(driver);
    }

    public boolean isNativeNotificationPage() {
        System.out.println("  check 'Notification' Screen loaded");
        return  !notificationPanel.isEmpty();
    }

    public boolean isClearAllBtnLoaded() {
        return !clearAllBtn.isEmpty();
    }

    public boolean tapClearAllBtn() {
        return tapElementInList_Android(clearAllBtn, 0);
    }

}

#3

I try it and it work ! Thanks !


#4

hello,
openNotifications() method not working. I applied it but it clears all notifications of app.
But i want to click on push based notifcation. Please help how to click on notification.


#5

driver.openNotifications() opens the notification panel, doesn’t click on any notification.

In order to do that, after you open the notification panel, you just find the element you are searching for and tap on it, like any normal test inside your application.


#6

i know it doesn’t click the notification . also it doesn’t opens the notification panel. notifications are dismissed using this method.


#7

Notifications are dismissed using clearNotifications method from Aleksei.

Using the driver.openNotifications just opens the notification panel… it doesn’t do anything else.


#8

it,s not opening the notification panel.
also can you please provide full solution to display notification and click on it.


#9

@shilpi driver.openNotifications opens Android! notification panel with most of Appium users :-). If it does not work with your case you should more investigate by yourself. Provide your code and Appium server logs. We are not possible to help you without zero knowledge about what device you have, what logs and what code.


#10

How to clear the notification without using driver.openNotifications();

I dont want click on the notifications but when iam doing any operation in the action title notifications are annoying how to clear those