Automate Android Deep Link Testing with Phoma Flows
Why deep link testing matters
Deep links are the primary entry points for marketing campaigns, push notifications, and cross‑app navigation. A broken link can silently drop users onto a generic screen or crash the app. Because the Android intent system resolves links at runtime, the same URL can behave differently depending on installed apps, OS version, or app state. Automating this verification eliminates manual regression cycles and guarantees that every supported link lands on the expected screen.
Prerequisites
- Windows PC with Phoma installed (Free tier is sufficient).
- One or more Android devices with USB debugging enabled and authorized.
- ADB available on the PC (Phoma bundles its own ADB, but you can also use a system‑wide install).
- The target app installed on each test device.
- A plain‑text CSV file that lists the deep‑link URLs you want to exercise (one per line, optional columns for expected screen identifiers).
Setting up ADB for deep link launch
Phoma can execute arbitrary shell commands via the Run Shell Command step. The most reliable way to fire a deep link is the am start command, which mimics the system’s intent resolution.
adb -s <serial> shell am start -W -a android.intent.action.VIEW -d "https://example.com/product/123" com.example.app
-s <serial>targets a specific device when several are attached.-Wmakes the command wait for the activity to launch, giving you a deterministic pause.-a android.intent.action.VIEWdeclares the standard view action.-dsupplies the URI.- The final package name (
com.example.app) forces the intent into your app; omit it if you want the system chooser.
Tip: Test the command manually in a terminal first. If it returns
Status=0and the app opens the expected screen, the command is ready for Phoma.
Building the base flow
Create a new flow in Phoma’s visual builder and add the following steps in order.
Step 1: Launch deep link via ADB
- Add a Run Shell Command step.
- Paste the
adb … am startcommand (without the device serial – Phoma fills it in per device). - Enable Continue on error = false so a failed launch stops the flow.
- Set a Timeout of 15 seconds; deep links that trigger network redirects may need a few extra seconds.
Step 2: Wait for target screen
After the intent fires, the app may show a loading spinner before the final UI appears.
- Add a Wait for Element step.
- Use a stable selector for a landmark element on the destination screen (e.g., a toolbar title, a unique
content‑description, or a resource‑id that does not change across releases). - Set Poll interval = 500 ms, Max wait = 10 s.
Step 3: Validate UI elements
- Add Read Text or Assert Element Exists steps for each critical widget (product name, price, “Add to cart” button).
- Optionally capture a Screenshot checkpoint for visual regression.
- If any assertion fails, the flow marks the run as Failed and you get a detailed report.
Making the flow data‑driven with a loop
Testing a single URL is trivial; the power comes from iterating over dozens or hundreds of links automatically.
Prepare a CSV of test URLs
Create deep_links.csv on the PC (or a shared network path accessible to the Phoma machine). Example:
url,expected_screen_id
https://example.com/product/123,product_detail
https://example.com/category/electronics,category_list
https://example.com/user/profile,profile_screen
Column url is the deep link.
Column expected_screen_id is a short identifier you can map to a selector in Phoma (e.g., a resource‑id prefix).
Add a Loop step and map variables
- Insert a Loop step at the very top of the flow.
- Choose Data source → CSV file and point to
deep_links.csv. - Phoma will expose each column as a flow variable:
${url}and${expected_screen_id}.
Insert variable into ADB command
Edit the Run Shell Command step from Step 1 and replace the hard‑coded URI with the variable:
adb -s ${device_serial} shell am start -W -a android.intent.action.VIEW -d "${url}" com.example.app
Phoma substitutes ${url} for each iteration. The ${device_serial} variable is automatically provided when the flow runs on multiple devices.
Dynamically choose the validation selector
Add a Conditional step after Wait for Element:
if ${expected_screen_id} == "product_detail" then
use selector: resourceId="com.example.app:id/product_name"
else if ${expected_screen_id} == "category_list" then
use selector: resourceId="com.example.app:id/category_title"
else
use selector: resourceId="com.example.app:id/profile_header"
end
Phoma’s visual condition builder lets you set the selector for the subsequent Wait for Element step based on the variable value, keeping the flow single‑source.
Handling multiple apps and fallback intents
Some deep links are universal (e.g., https://example.com/...) and may open a chooser if several apps claim the domain. To force your app:
- Keep the package name in the
am startcommand (as shown above). - If you want to test the chooser, omit the package and add a Wait for Element that looks for the system resolver dialog (
android:id/resolver_list). Then add a Tap step on your app’s entry and continue.
Running the flow on many devices
Phoma’s Device Pool feature lets you select a group of authorized phones. When you start the flow:
- Choose Run on device pool → QA‑Lab.
- Phoma spawns a parallel instance per device, each receiving its own
${device_serial}. - The CSV loop runs independently on every device, giving you a matrix of devices × URLs.
Result aggregation: After the run, the dashboard shows a grid – green for passed, red for failed – with drill‑down logs per device‑URL pair.
Scheduling and reporting
- Open the Schedule tab, create a new job (e.g., Nightly Deep Link Regression).
- Set Cron =
0 2 * * *(2 AM daily). - Enable Email on failure and attach the HTML report.
- For CI integration, export the run summary via the HTTP Request step at the end of the flow (POST JSON to your internal dashboard).
Tips for stable selectors
- Prefer resource‑id over text or content‑description; IDs survive language changes.
- Use partial matches (
starts-withorcontains) when the ID includes a dynamic suffix. - Anchor to a parent container that is unique (e.g., a
RecyclerViewwith a knownresource-id) then navigate to the child via index only when necessary. - Document each selector in a shared spreadsheet so the team can review when the app updates.
Troubleshooting common issues
| Symptom | Likely cause | Fix |
|---|---|---|
am start returns Error: Activity not started |
Package name typo or app not installed | Verify `pm list packages |
| Flow hangs at Wait for Element | Selector no longer matches (UI changed) | Update selector; use the Element Explorer in Phoma to capture the new tree. |
| CSV variable not substituted | Variable name mismatch (case‑sensitive) | Ensure column header exactly matches ${url} (lower‑case). |
| Multiple devices but only one runs | Device pool not selected or devices unauthorized | Run adb devices – all must show device, not unauthorized. |
| Screenshot checkpoint fails on different screen densities | Image comparison is pixel‑perfect | Switch to OCR‑based text assertion or increase tolerance in the checkpoint settings. |
Summary
By combining Phoma’s Run Shell Command step with the am start intent, a Loop over a CSV data source, and conditional selector logic, you obtain a maintainable, data‑driven test suite that validates every deep link across any number of physical devices. The flow runs locally on your Windows machine, costs nothing for unlimited phones on the free tier, and can be scheduled for nightly regression or triggered on demand from your CI pipeline. Start with a handful of critical URLs, expand the CSV as new campaigns launch, and you’ll catch broken entry points before they reach users.
