[{"data":1,"prerenderedAt":20},["ShallowReactive",2],{"blog-post-en-automate-push-notification-testing-android-phoma":3},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":15,"thumbnail_url":16,"translations":17,"body":18,"asset_base":19},"automate-push-notification-testing-android-phoma","en","Automate Push Notification Testing on Android with Phoma","Learn how to reliably trigger, capture, and verify Android push notifications in Phoma flows across multiple devices.","2026-11-20",[10,11,12,13,14],"push-notifications","android-testing","phoma","automation","qa",[10,11,12,13,14],"https://blog-api.phomaapp.com/api/blog/posts/automate-push-notification-testing-android-phoma/thumbnail.svg?lang=en",[5],"## Why push‑notification testing matters\n\nPush notifications are a primary engagement channel for most Android apps. A broken payload, missing deep‑link handling, or a UI that doesn’t react to the notification can silently degrade user retention. Manual testing is slow, flaky, and impossible to repeat on dozens of devices. Phoma lets you turn the whole cycle — send, receive, act, assert — into a single visual flow that runs on any number of phones attached to your Windows PC.\n\n## Prerequisites\n\n1. **Phoma installed** on Windows with at least one Android device connected (USB or wireless ADB).\n2. **Notification access** granted to the app under test (Settings → Apps → Special access → Notification access).\n3. **FCM server key** or any HTTP endpoint that can push a test message to the device (you can also use the Firebase console for ad‑hoc sends).\n4. **Phoma Team/Business plan** if you want to run the same flow on a device pool simultaneously.\n\n## Overview of the flow\n\n| Step | Purpose | Phoma step type |\n|------|---------|-----------------|\n| 1 | Send a test push via HTTP request | **HTTP Request** |\n| 2 | Wait for the notification to appear in the shade | **Wait for Element** (selector targets `android.service.notification.NotificationListenerService`) |\n| 3 | Expand the notification and tap the action button | **Tap** (selector on the action’s `android:id/action_button`) |\n| 4 | Verify the app opens on the expected screen | **Wait for Element** + **Text Assertion** |\n| 5 | Capture a screenshot for the run report | **Screenshot** |\n| 6 | (Optional) Loop over a list of payload variants | **Loop** + **Variable** |\n\n## Step‑by‑step construction\n\n### 1. Send the push with an HTTP Request step\n\nAdd an **HTTP Request** step at the top of the flow. Use the FCM legacy HTTP API (or your own push gateway). The request body is a JSON payload; you can parameterise the `title`, `body`, and `data` fields with flow variables so the same flow can test multiple scenarios.\n\n```json\n{\n  \"to\": \"{{device_fcm_token}}\",\n  \"notification\": {\n    \"title\": \"{{push_title}}\",\n    \"body\": \"{{push_body}}\"\n  },\n  \"data\": {\n    \"deep_link\": \"{{deep_link_url}}\",\n    \"test_id\": \"{{test_id}}\"\n  }\n}\n```\n\nSet **Method** → `POST`, **URL** → `https://fcm.googleapis.com/fcm/send`, **Headers** → `Authorization: key={{fcm_server_key}}` and `Content-Type: application/json`. Store the server key and each device’s registration token in Phoma’s **Variables** panel (they are encrypted at rest).\n\n### 2. Wait for the notification to appear\n\nAndroid surfaces notifications in the system shade, which is part of the `NotificationListenerService` UI tree. Add a **Wait for Element** step with a selector that matches the notification’s package name and a stable attribute such as `android:text` containing the push title variable.\n\n```text\n// Example selector (UIAutomator syntax)\nnew UiSelector().packageName(\"com.android.systemui\").textContains(\"{{push_title}}\")\n```\n\nSet **Timeout** to 30 s and **Poll Interval** to 1 s. If the notification never arrives, the flow fails fast and the run report shows the HTTP response from step 1 for quick debugging.\n\n### 3. Expand and tap the action button\n\nNotifications may be collapsed. Use a **Tap** step on the expand affordance (`android:id/expand_button`) followed by a second **Tap** on the action button you care about (e.g., “Open”). Because the shade UI is transient, chain the two taps without an explicit wait; Phoma’s built‑in retry logic handles the brief animation.\n\n```text\n// Expand\nnew UiSelector().resourceId(\"android:id/expand_button\")\n// Action button (usually the first action)\nnew UiSelector().resourceId(\"android:id/action_button\").instance(0)\n```\n\n### 4. Verify the deep‑link landing screen\n\nAfter the tap, the app should launch and navigate to the screen encoded in `deep_link`. Add a **Wait for Element** that targets a unique element on that screen — for example a toolbar title or a RecyclerView item with the `test_id` you sent in the data payload.\n\n```text\nnew UiSelector().resourceId(\"com.example.app:id/toolbar_title\").text(\"{{expected_screen_title}}\")\n```\n\nFollow with a **Text Assertion** step to confirm the exact copy, and a **Screenshot** step to capture visual evidence. The screenshot is automatically attached to the run report and can be compared across devices.\n\n### 5. Parameterise multiple payloads with a Loop\n\nCreate a **Variable** named `payloads` that holds a JSON array of test cases (title, body, deep_link, expected_screen_title). Add a **Loop** step that iterates over `payloads`. Inside the loop, map each array entry to the flow variables used in steps 1‑4 (`push_title`, `push_body`, `deep_link_url`, `expected_screen_title`, `test_id`). This yields a single flow that validates dozens of notification permutations in one run.\n\n```json\n[\n  {\"push_title\":\"Promo\", \"push_body\":\"20% off\", \"deep_link_url\":\"app://promo/20\", \"expected_screen_title\":\"Promo Details\", \"test_id\":\"promo_20\"},\n  {\"push_title\":\"Alert\", \"push_body\":\"Server down\", \"deep_link_url\":\"app://alert/server\", \"expected_screen_title\":\"Incident View\", \"test_id\":\"alert_server\"}\n]\n```\n\n### 6. Run on many phones at once\n\nIf you have a device pool (Team/Business plan), open the **Run Configuration** dialog, select **All devices in pool**, and enable **Parallel execution**. Phoma will dispatch the same flow to every connected phone, each using its own FCM token variable. The run dashboard aggregates pass/fail per device, making it trivial to spot a model‑specific regression.\n\n## Handling common pitfalls\n\n| Symptom | Root cause | Fix |\n|---------|------------|-----|\n| Notification never appears | Device not registered for FCM or token stale | Refresh token in app, update `device_fcm_token` variable, ensure `google-services.json` is current. |\n| Flow taps wrong action button | Multiple actions, index shifts | Use a selector that matches the action’s `android:text` (e.g., `text(\"Open\")`) instead of `instance(0)`. |\n| Deep link opens a fallback screen | Intent filter missing or data schema mismatch | Verify `AndroidManifest.xml` declares `\u003Cdata android:scheme=\"app\" android:host=\"promo\"/>`. |\n| Screenshot shows system shade still open | Tap executed before animation finished | Insert a short **Wait** step (500 ms) after the expand tap, or enable **Wait for UI idle** in the step settings. |\n\n## Extending the pattern\n\n* **Rich notifications** – Add a step that reads the `android:progress` or `android:bigText` via **Read Text** and asserts the formatted content.\n* **Silent pushes** – Omit the `notification` block, send only `data`, then start the app with an **Open App** step and verify background processing (e.g., local database update) using a **Run Shell** step (`adb shell dumpsys package com.example.app`).\n\n## Checklist before you ship\n\n- [ ] All device FCM tokens are current and stored as encrypted variables.\n- [ ] Notification access is granted on every test phone.\n- [ ] Selectors use stable attributes (`resourceId`, `text`, `contentDescription`) rather than fragile indices.\n- [ ] Loop payloads cover happy path, empty payload, malformed deep link, and locale variations.\n- [ ] Run the flow on at least three device models (low‑end, flagship, tablet) in parallel.\n- [ ] Review the aggregated run report; any flaky step should be hardened with a longer timeout or an explicit wait.\n\n## TL;DR\n\n1. **Send** a push via HTTP Request (parameterised).\n2. **Wait** for the system notification using a UIAutomator selector on the shade.\n3. **Expand** and **tap** the desired action button.\n4. **Assert** the app lands on the correct deep‑link screen (text + screenshot).\n5. **Loop** over a JSON array of test cases to cover many scenarios in one flow.\n6. **Run** in parallel on a device pool for instant cross‑device coverage.\n\nWith this pattern you turn a traditionally manual, error‑prone QA task into a repeatable, version‑controlled Phoma flow that runs on any number of Android phones from a single Windows workstation.\n","https://blog-api.phomaapp.com/api/blog/posts/automate-push-notification-testing-android-phoma/assets",1796035639613]