[{"data":1,"prerenderedAt":20},["ShallowReactive",2],{"blog-post-en-build-data-driven-phoma-flows-remote-json":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},"build-data-driven-phoma-flows-remote-json","en","Build Data‑Driven Phoma Flows That Pull Test Inputs from a Remote JSON Endpoint","Learn how to fetch test data from a remote JSON source and loop through it in Phoma, so a single flow can run many scenarios without hard‑coding values.","2026-12-04",[10,11,12,13,14],"data-driven","http-request","test-automation","phoma-flows","json",[10,11,12,13,14],"https://blog-api.phomaapp.com/api/blog/posts/build-data-driven-phoma-flows-remote-json/thumbnail.svg?lang=en",[5],"## Why data‑driven flows matter\n\nHard‑coding usernames, product IDs, or search terms inside a flow makes maintenance painful. When the test matrix grows — different accounts, regions, or feature flags — you end up duplicating the same flow or editing it every run. A data‑driven approach lets you keep the **what** (the flow logic) separate from the **which** (the test inputs). Phoma’s **HTTP Request** step, combined with **Loop** and **Condition** steps, gives you everything you need to pull a JSON array from a URL and iterate over it, all without writing code.\n\n## Prerequisites\n\n- Phoma installed on Windows and at least one Android phone connected (USB or Wi‑Fi).\n- A place to host a static JSON file that Phoma can reach via HTTP/HTTPS. Good options:\n  - A GitHub Gist (raw URL).\n  - A private GitHub repository with GitHub Pages enabled.\n  - A tiny local HTTP server (`python -m http.server 8000`) if the PC and phone are on the same LAN.\n- Basic familiarity with Phoma’s visual builder: adding steps, setting selectors, and using variables.\n\n## 1. Design the JSON test‑data contract\n\nKeep the schema simple and version‑tolerant. Each object in the top‑level array represents one test case. Example `test‑cases.json`:\n\n```json\n[\n  {\n    \"id\": \"login‑valid‑01\",\n    \"username\": \"alice@example.com\",\n    \"password\": \"Secret123!\",\n    \"expectedToast\": \"Welcome, Alice\"\n  },\n  {\n    \"id\": \"login‑invalid‑02\",\n    \"username\": \"bob@example.com\",\n    \"password\": \"wrong\",\n    \"expectedToast\": \"Invalid credentials\"\n  },\n  {\n    \"id\": \"login‑empty‑03\",\n    \"username\": \"\",\n    \"password\": \"\",\n    \"expectedToast\": \"Please enter credentials\"\n  }\n]\n```\n\n*Why this shape?*\n- `id` gives you a stable key for logging and screenshots.\n- Flat fields map directly to Phoma variables (username, password, expectedToast).\n- Adding new fields later (e.g., `deviceTag`) won’t break existing flows.\n\nHost the file and note the **raw** URL (e.g., `https://gist.githubusercontent.com/yourname/abc123/raw/test-cases.json`).\n\n## 2. Create a new flow in Phoma\n\n1. Open Phoma → **Flows** → **New Flow**.\n2. Name it `Data‑Driven Login Test`.\n3. Set **Target App** to the package you’re testing (e.g., `com.example.myapp`).\n\n## 3. Add the HTTP Request step to fetch the JSON\n\n1. Click **+ Step** → **HTTP Request**.\n2. Configure:\n   - **Method**: `GET`\n   - **URL**: paste your raw JSON URL.\n   - **Response Type**: `JSON` (Phoma will parse the body into a variable).\n   - **Variable Name**: `testCases` (this becomes a list variable you can loop over).\n3. **Run once** to verify the request succeeds (green check). You should see the array length in the run log.\n\n> **Tip:** If the endpoint requires authentication, add headers in the **Headers** table (e.g., `Authorization: Bearer \u003Ctoken>`).\n\n## 4. Loop over the test cases\n\n1. Add a **Loop** step **after** the HTTP Request.\n2. Set **Loop Type** → **For each item in variable**.\n3. Choose variable `testCases`.\n4. Phoma creates a **loop block**; everything you drag inside will execute once per array element.\n\nInside the loop you now have access to the current item’s fields via dot notation: `item.username`, `item.password`, `item.expectedToast`, `item.id`.\n\n## 5. Build the per‑iteration logic\n\n### 5.1 Open the app and reach the login screen\n\n- **Step**: *Open App* → package `com.example.myapp`.\n- **Step**: *Wait for Element* → selector for the username field (e.g., `resourceId=com.example.myapp:id/et_username`).\n\n### 5.2 Type credentials from the current item\n\n- **Step**: *Type Text* → target the username field, text `{{item.username}}`.\n- **Step**: *Type Text* → target the password field, text `{{item.password}}`.\n\n> Phoma resolves `{{item.username}}` at runtime for each iteration.\n\n### 5.3 Submit and verify\n\n- **Step**: *Tap* → login button selector.\n- **Step**: *Wait for Element* → toast or success screen selector.\n- **Step**: *Read Text* → capture the toast message into variable `actualToast`.\n- **Step**: *Condition* → **If** `actualToast == {{item.expectedToast}}` then **Pass** else **Fail**.\n- **Step**: *Screenshot* → name `{{item.id}}_result.png` (useful for later review).\n\n### 5.4 Clean up for next iteration\n\n- **Step**: *Press Keys* → `BACK` (or *Close App*) to return to a known state.\n- **Step**: *Wait* → 500 ms (prevents race conditions).\n\n## 6. Run the flow on one or many devices\n\n- In the **Run** dialog, pick a single phone or a device group.\n- Enable **Run on all selected devices** if you want the same data matrix on multiple phones (e.g., different OS versions).\n- Click **Run**.\n\nPhoma will:\n1. Fetch the JSON once per run (not per device).\n2. For each device, iterate the loop, substituting the current item’s values.\n3. Produce a run report with a row per iteration per device, plus the screenshots you named.\n\n## 7. Extend the pattern\n\n| Need | How to add it |\n|------|----------------|\n| **Different environments** (staging vs prod) | Host separate JSON files (`test-cases-staging.json`, `test-cases-prod.json`) and parameterize the URL with a Phoma **Run Variable** (set at run time). |\n| **Dynamic data** (e.g., generated OTP) | Add a second HTTP Request *inside* the loop that calls your OTP service, store the response in `item.otp`, then type `{{item.otp}}`. |\n| **Parallel execution** | Create a **Sub‑Flow** containing the per‑iteration logic, then call it from the loop with **Run Sub‑Flow** (Phoma runs each sub‑flow sequentially; for true parallelism, duplicate the flow per device group). |\n| **Reporting to a dashboard** | After the loop, add an **HTTP Request** (POST) that sends a summary JSON (`{flow: \"Data‑Driven Login\", passes: 2, fails: 1}`) to your internal API. |\n\n## 8. Troubleshooting checklist\n\n- **HTTP Request fails** → verify URL is reachable from the PC (open in browser). Check firewall / VPN.\n- **JSON parsing error** → ensure the response is valid JSON (no trailing commas, correct encoding).\n- **Loop never runs** → confirm `testCases` variable is an array; a single object will not iterate.\n- **Variable substitution not working** → use double curly braces `{{item.field}}` exactly; Phoma does not support `$` syntax.\n- **Selector flakiness** → prefer stable attributes (`resourceId`, `content-desc`) over text; see “Choose Stable Android Element Selectors for Phoma Flows” for deeper guidance.\n\n## 9. Full flow outline (copy‑paste into Phoma’s export/import if you use JSON export)\n\n```text\nFlow: Data‑Driven Login Test\nSteps:\n1. HTTP Request (GET) → variable testCases\n2. Loop (for each item in testCases)\n   2.1 Open App (com.example.myapp)\n   2.2 Wait for Element (username field)\n   2.3 Type Text → {{item.username}}\n   2.4 Type Text → {{item.password}}\n   2.5 Tap (login button)\n   2.6 Wait for Element (toast)\n   2.7 Read Text → actualToast\n   2.8 Condition: actualToast == {{item.expectedToast}}\n   2.9 Screenshot → {{item.id}}_result.png\n   2.10 Press Keys (BACK)\n   2.11 Wait (500 ms)\n3. End Loop\n```\n\n## 10. Next steps\n\n- **Version your test data** alongside your app releases (Git tags).\n- **Add a CI step** that runs the flow nightly via Phoma’s scheduler (see “Schedule Unattended Phoma Flows on Android Test Phones”).\n- **Share the flow** with your team using Phoma’s Team plan so everyone runs the same data‑driven matrix.\n\nBy pulling test inputs from a remote JSON endpoint, you turn a single Phoma flow into a reusable test harness that scales with your test matrix — no code, no duplicate flows, and a single source of truth for test data.\n","https://blog-api.phomaapp.com/api/blog/posts/build-data-driven-phoma-flows-remote-json/assets",1796464663297]