Search code examples
androidpush-notificationautomationautomated-testsappium

Push Notification Automation using Appium


How to automate test case to assert when push notification is received on android using appium automation?

I want to automate the test case when push notification is received. How to check if push notification is received? How to check if the push notification is from my app (package) ? How to assert that this push notification is mine and received successfully?


Solution

  • You can use below code to get all notification titles and then iterate it.

        driver.openNotifications();
    
        List<WebElement> allnotifications=driver.findElements(By.id("android:id/title"));
    
        for (WebElement webElement : allnotifications) {
            System.out.println(webElement.getText());
            if(webElement.getText().contains("something")){
                System.out.println("Notification found");
                break;
            }
        }