Enhancing Android App Automation by Implementing Push Notification Automation at Halodoc

automation Sep 27, 2024

At Halodoc, ensuring that our mobile applications work flawlessly is critical to delivering a seamless user experience. Push notifications are essential for keeping users, including doctors and patients, informed and engaged. For instance, doctors receive timely alerts about patient requests, while patients are informed about follow-ups from their doctors. Given their importance, it's crucial to test these notifications rigorously. For a deeper exploration of the challenges we encountered and the benefits of automating push notifications, please refer to our blog.

In this blog, we detail how we leverage Appium to automate the testing of push notifications in our Android app. We will cover our approach to setting up automated tests, the specific challenges we encountered, and the solutions we implemented to ensure accurate and reliable notifications.

Technologies and Tools for Push Notification Automation

We utilise Appium, a robust tool for automating mobile application testing. With Appium, we automate push notifications testing by simulating various user scenarios to verify that notifications are delivered and displayed accurately at the right time. Our setup also supports testing notifications in multiple languages, such as English and Bahasa, ensuring they are properly displayed for users across different regions.

To learn more about Appium and the Android Test Suite, please refer to our Cucumber Framework with Appium for Android blog.

Key Steps to Manually Test Push Notifications

Before transitioning to automation, push notifications testing required several detailed manual steps to verify notifications across different app states and user interactions. Here's a breakdown of the manual process:

  1. Opening the Notification Panel: Manually swipe down the notification bar to view notifications.
  2. Clearing Notification Panel: Ensure the notification panel is cleared of any previous notifications.
  3. Triggering Notifications: Manually initiate notifications either through the app's flow or by using the API.
  4. Verifying Notification Content:Review each notification manually to ensure that the displayed content (text, icons, and buttons) matches the expected values for the scenario being tested.
  5. Interacting with Notifications:To simulate user interactions, manually tap or swipe notifications, verifying that the in-app behaviours—such as navigating to a specific screen or dismissing the notification—function as expected.
  6. Tracking Outcomes: After interacting with the notification, manually check the app's response or analyse log files to confirm that the triggered behaviours were correct. This step often required repeated testing to cover different scenarios.

Testing Notifications Across Different App States:

  • App in Foreground: Monitor notifications while the app is open to ensure they display correctly without disrupting active processes.
  • App in Background: Switch the app to the background, trigger notifications, and verify their appearance in the notification tray.
  • App Closed: With the app fully closed, check if notifications are still delivered and verify that tapping them brings the app back to the foreground.
  • Device Locked: Lock the device and observe whether notifications appear on the locked screen. After unlocking, confirm if the notifications behave as expected.

While this manual approach was thorough, it was also time-consuming and repetitive. To enhance efficiency, we introduced automation for push notifications testing, which allowed us to streamline and scale these steps across multiple app states and scenarios.

Step-by-Step Guide to Implementing Push Notification Automation

Step 1: Opening and Clearing Notifications: Before beginning tests, ensure that existing notifications are cleared to maintain a clean testing environment. Here’s how to do it:

  • Open the notification bar using the driver.openNotifications() method:
  • Clear all notifications and return to the app by pressing back button by locating the "Clear All" button with the ID clear_all_button and clicking it:

Step 2: Triggering Notifications: To automate push notifications effectively, we can initiate them either through user actions in the app or by sending backend API requests. This approach allows us to test notifications in various scenarios.

For example, in the case of booking a lab test, the notification can be triggered by simulating the entire user flow where a user books a lab test through the app's UI. This mirrors how users interact with the app, triggering a push notification upon successful booking. Alternatively, the same notification can be triggered by directly interacting with the backend system. In this case, an API request is made to book or update the lab order, which will also trigger the push notification without the need to navigate through the app’s interface. By combining both UI-driven and backend-triggered flows, we ensure that push notifications are thoroughly tested for accuracy and reliability, whether they originate from user actions or backend events.

Step 3: Locating the Notification: Once the notification is triggered and displayed in the notification tray, you need to interact with it. Here’s how to handle the notification:

  • Re-open the notification tray using driver.openNotifications();
  • Identify the notification using a suitable locator, such as XPath

Step 4: Verifying Push Notification Content: In this step, the focus is on validating the content of the push notification to ensure that it has been displayed correctly. You need to confirm that the notification is visible and that the content, such as the header, sub-header, and any other relevant information, matches the expected values for that test scenario. This verification ensures that the notification data is accurate and that the user receives the intended message.

For example, The test ensures that the push notification's header and sub-header are displayed accurately, confirming the correct delivery of important information to the user.

Step 5: Interacting with Notifications: Once the notification appears, we verify that it exists using the isElementVisible() property. If the notification is present, we simulate user interaction by tapping on it, which will trigger the associated app behaviour.

Step 6: Verifying Push Notifications in Different App States: In Android, push notifications behave differently depending on the app's state—whether it is in the foreground, background, or terminated (killed). To ensure comprehensive testing, we verify that push notifications function correctly in all scenarios using the example of booking a lab order:

  • App in Foreground: When the app is active and running, notifications are handled directly within the app’s UI. For example, if a user books a lab order while the app is in the foreground, the push notification will be handled internally. Upon tapping the notification, the user should be navigated to the Order Details page, regardless of where they are within the app.
  • App in Background: When the Android app is running in the background, notifications will appear in the system notification tray. Tapping on the notification should bring the app back to the foreground and navigate the user directly to the appropriate screen, such as the Order Details page for a booked lab order. This ensures that users can seamlessly access important information without needing to manually navigate back to the app or relevant page.
  • App in Terminated (Killed) State: When the Android app is completely closed (not running in the background), notifications will still appear in the system notification tray. Upon tapping the notification, the app should relaunch and navigate the user directly to the relevant screen, such as the Order Details page for a booked lab order. This ensures that even if the app was not previously running, the user is smoothly guided to the necessary information without additional steps.

By verifying push notifications in these different app states, we ensure that users experience a seamless flow from the notification to the desired screen, regardless of the app's state.

Step 7: Ensuring Correct Navigation: Verifying that tapping on a Push Notification navigates to the correct page within the app is essential for validating the user experience and the notification flow. For example, after successfully booking a lab order, we ensure that the push notification directs the user to the Order Details page with a 'Booked' status, where they can view the specifics of their booking.

Step 8: Clean Up: Before running the next test, it’s important to clean up the environment by closing the app and resetting the device state. This ensures that previous test results don’t affect the current session.

Automation Limitations:

  • Accessing Group Notifications: Accessing group notifications with tools like Appium can be challenging due to their limited access to system-level notifications. When multiple notifications are sent simultaneously, they are often grouped into a single notification, which complicates the process of identifying and interacting with specific notifications through XPath. A potential solution to this issue is utilizing backend API capabilities to inject a unique groupID for testing purposes. By doing so, notifications can remain distinct and avoid being grouped, enabling more effective automation testing, as each notification can be accurately identified and interacted with using Appium.
  • Timing Issues and Notification Delays: Push notifications may experience delays due to server or network issues, which can impact test timing. To address this, implement smart waits in your automation scripts to ensure sufficient time for notifications to arrive. This approach helps prevent false negatives caused by delayed delivery and ensures that your tests accurately reflect notification behaviour.

Conclusion

Automating push notification testing with Appium has significantly enhanced our testing process, addressing key challenges while improving accuracy.By streamlining the handling and validation of notifications, we ensure a seamless user experience and maintain high application quality standards. For a detailed discussion of the overall benefits and our iOS implementation, please refer to our  blog.

References

Enhancing App Automation by Implementing Push Notification Automation at Halodoc.
At Halodoc, ensuring efficient and thorough testing of our mobile applicationsis paramount. Push notifications are a critical feature we test extensively, asthey play a vital role in maintaining user engagement and ensuring timelycommunication. Notifications inform doctors when they receive pat…
Enhancing iOS App Automation by Implementing Push Notification Automation at Halodoc.
At Halodoc, ensuring efficient and thorough testing of our mobile applicationsis paramount. One critical feature we test extensively is push notifications,which play a vital role in maintaining user engagement and ensuring timelycommunication with our users. For instance, notifications might noti…
Handle android push notification using appium - qavalidation
Push notification is a message pop up to any mobile device and can be sent from any app that is installed on device. There are situation we need to test or verify if push notification is working as expected for the app we are currently testing. Appium has the ability to handle push notifications, ev…
Play with Automating Notifications
We know that notifications are playing a major role in mobile devices for quick references, to take quick navigation and fast response. Nowadays retrieving the information from notificati…
Can we get device notifications using AndroiDriver
Till the part to opening notification shade there isn’t any problem. But whenever I try to locate the notification of my app using the text driver.findElement(By.xpath(”//android.widget.TextView[@text=‘TitleText’]”)); I am not able to click it because this textview is not clickable. Also, whenever I…

Join Us

Scalability, reliability, and maintainability are the three pillars that govern what we build at Halodoc Tech. We are actively looking for engineers at all levels and if solving hard problems with challenging requirements is your forte, please reach out to us with your resume at careers.india@halodoc.com.

About Halodoc

Halodoc is the number one all-around healthcare application in Indonesia. Our mission is to simplify and bring quality healthcare across Indonesia, from Sabang to Merauke. We connect 20,000+ doctors with patients in need through our Tele-consultation service. We partner with 3500+ pharmacies in 100+ cities to bring medicine to your doorstep. We've also partnered with Indonesia's largest lab provider to provide lab home services, and to top it off, we have recently launched a premium appointment service that partners with 500+ hospitals that allow patients to book a doctor appointment inside our application. We are extremely fortunate to be trusted by our investors, such as the Bill & Melinda Gates Foundation, Singtel, UOB Ventures, Allianz, GoJek, Astra, Temasek, and many more. We recently closed our Series D round and in total have raised around USD 100+ million for our mission. Our team works tirelessly to make sure that we create the best healthcare solution personalized for all of our patient's needs, and are continuously on a path to simplify healthcare for Indonesia.

Yogeshwari G N

Software Development Engineer In Test