[{"data":1,"prerenderedAt":20},["ShallowReactive",2],{"blog-post-en-building-reusable-subflows-phoma-modular-test-automation":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},"building-reusable-subflows-phoma-modular-test-automation","en","Building Reusable Sub-Flows in Phoma for Modular Test Automation","Learn how to create, version, and reuse sub-flows in Phoma to keep automation maintainable across many test cases.","2026-11-13",[10,11,12,13,14],"phoma","automation","subflows","testing","modular",[10,11,12,13,14],"https://blog-api.phomaapp.com/api/blog/posts/building-reusable-subflows-phoma-modular-test-automation/thumbnail.svg?lang=en",[5],"## Why sub‑flows matter\n\nWhen you automate the same login sequence, navigation path, or data‑entry pattern in dozens of test cases, copying those steps into every flow creates three problems:\n\n1. **Maintenance burden** – a UI change forces you to edit every copy.\n2. **Inconsistent behavior** – small variations creep in (different wait times, alternate selectors).\n3. **Team friction** – reviewers can’t tell whether a flow uses the canonical version.\n\nPhoma solves this with *sub‑flows*: a flow that can be called from another flow as a single step. The caller sees one “Run Sub‑Flow” block, while the sub‑flow contains the detailed steps. Updating the sub‑flow instantly propagates to all callers.\n\n## Core concepts\n\n| Concept | Description |\n|---------|-------------|\n| **Sub‑flow** | A regular Phoma flow marked *Reusable*. It has its own start/end, variables, and can be invoked from any other flow. |\n| **Input / output parameters** | Named values passed into the sub‑flow and returned to the caller. They appear as fields on the “Run Sub‑Flow” step. |\n| **Version tag** | A free‑text label (e.g., `v1.2-login`) you assign when you publish a change. Callers can pin a specific version or always use *Latest*. |\n| **Scope** | Sub‑flows live in the same project as the calling flow, so they share the same device pool and credentials.\n\n## Step‑by‑step: creating a reusable login sub‑flow\n\n### 1. Build the atomic steps\n1. Open Phoma → **New Flow** → name it `Login_SubFlow`.\n2. Add the following steps (use the visual builder, no code):\n   - **Wait for element** – selector `resourceId:com.example.app:id/username_field`\n   - **Type text** – value `${username}` (parameter)\n   - **Wait for element** – selector `resourceId:com.example.app:id/password_field`\n   - **Type text** – value `${password}` (parameter)\n   - **Tap** – selector `resourceId:com.example.app:id/login_button`\n   - **Wait for element** – selector `resourceId:com.example.app:id/home_screen_marker` (confirms success)\n3. In the flow settings, enable **Reusable** and add two *input parameters*: `username` (string) and `password` (string). No output parameters are needed for this example.\n\n### 2. Publish a version\n1. Click **Publish** → enter a version tag `v1.0-login`.\n2. Phoma stores the flow definition and the tag. You can later publish `v1.1-login` after adjusting a wait time.\n\n### 3. Call the sub‑flow from a test case\n1. Create a new flow `Smoke_Test_Home`.\n2. Add a **Run Sub‑Flow** step.\n3. In the step config:\n   - **Sub‑flow** → select `Login_SubFlow`.\n   - **Version** → choose *Latest* (or pin `v1.0-login`).\n   - **Inputs** → map `${testUser}` → `username`, `${testPass}` → `password`.\n4. Continue with the rest of the smoke test (e.g., navigate to settings, assert version).\n\n### 4. Run and verify\n- Execute `Smoke_Test_Home` on a single device. The run log shows the sub‑flow steps expanded under the **Run Sub‑Flow** node, making debugging transparent.\n- Change the login UI (e.g., new resource‑id). Edit `Login_SubFlow`, publish `v1.1-login`. All callers using *Latest* automatically pick up the fix.\n\n## Parameter patterns for real‑world scenarios\n\n### Multiple environments\n```json\n{\n  \"env\": \"staging\",\n  \"username\": \"qa_user\",\n  \"password\": \"${secrets.staging_pwd}\"\n}\n```\nPass `env` as an input; inside the sub‑flow use a **Condition** step to select the correct base URL or API endpoint.\n\n### Returning data to the caller\nIf the login flow also fetches a session token, add an *output parameter* `sessionToken`. In the sub‑flow’s final step, use **Set Variable** → `sessionToken = ${lastHttpResponse.body.token}`. The caller can then use `${sessionToken}` in subsequent HTTP Request steps.\n\n### Optional steps with defaults\nMark parameters as *optional* and provide default values in the sub‑flow settings. Callers that omit the parameter get the default (e.g., a generic test user).\n\n## Version‑pinning strategy for teams\n\n| Strategy | When to use | How to enforce |\n|----------|-------------|----------------|\n| **Always Latest** | Fast‑moving prototypes, solo developers | Default in Phoma; no extra config. |\n| **Pin to tag** | Regression suites that must stay stable | In each **Run Sub‑Flow** step, set *Version* to a specific tag (`v1.0-login`). |\n| **Semantic tags** | CI pipelines that promote `v1.x` → `v2.x` after review | Publish tags like `v1.2-login`, `v2.0-login`. CI script reads the tag from a manifest file.\n\n**Tip:** Keep a `versions.md` in your repo (or Phoma project notes) listing each tag, date, and change summary. This gives auditors a clear trail without a separate CI system.\n\n## Organising sub‑flows in a project\n\n1. **Folder convention** – Phoma lets you create folders in the flow list. Use `subflows/auth`, `subflows/navigation`, `subflows/data-entry`.\n2. **Naming** – Prefix with domain: `auth_login`, `nav_open_settings`, `data_enter_profile`.\n3. **Documentation** – Add a **Description** field on each sub‑flow (Markdown supported). Example:\n   ```markdown\n   ## auth_login\n   Logs a user into the app.\n   **Inputs**: `username`, `password`\n   **Outputs**: `sessionToken`\n   **Assumptions**: App is on the login screen.\n   ```\n4. **Access control** – In Team/Business plans, set *View* permission for all, *Edit* only for the owning squad. This prevents accidental edits to shared login logic.\n\n## Debugging a failing sub‑flow call\n\n1. Open the **Run Log** of the parent flow.\n2. Expand the **Run Sub‑Flow** node – you see every inner step with its own pass/fail status.\n3. If a selector fails, click the step → **Inspect Element** → Phoma opens the live UI tree on the device. Adjust the selector, then **Update Sub‑Flow** and publish a new tag.\n4. Re‑run the parent flow; it will automatically use the new version if set to *Latest*.\n\n## Example: end‑to‑end checkout test using three sub‑flows\n\n```text\nSmoke_Test_Checkout\n ├─ Run Sub‑Flow: auth_login (v1.1-login)\n ├─ Run Sub‑Flow: nav_open_cart (v1.0-cart)\n ├─ Run Sub‑Flow: data_enter_shipping (v1.2-shipping)\n ├─ Tap: place_order_button\n └─ Assert: order_confirmation_text\n```\n\nEach sub‑flow encapsulates a distinct UI area. When the shipping screen changes, only `data_enter_shipping` needs an update. The checkout test remains untouched.\n\n## Best‑practice checklist\n\n- [ ] **Single responsibility** – a sub‑flow does one logical thing (login, navigate, fill form).\n- [ ] **Explicit parameters** – avoid hidden globals; pass everything via inputs/outputs.\n- [ ] **Version tags on every publish** – never rely on an unnamed “latest” in CI.\n- [ ] **Document assumptions** – e.g., “app must be on home screen”.\n- [ ] **Test sub‑flows in isolation** – run them alone on a clean device before integrating.\n- [ ] **Review changes with the team** – use Phoma’s built‑in diff view when publishing a new tag.\n\n## Scaling to many devices\n\nBecause sub‑flows are just flows, Phoma’s **Run on Multiple Devices** feature works unchanged. The run report aggregates sub‑flow results per device, so you can spot a flaky login on a specific model instantly.\n\n## Summary\n\nReusable sub‑flows turn a collection of repetitive steps into a single, versioned building block. By defining clear inputs/outputs, publishing semantic tags, and organising them in folders, you get:\n\n- **Faster maintenance** – one edit fixes dozens of tests.\n- **Predictable CI** – pinned versions guarantee reproducibility.\n- **Team confidence** – reviewers see exactly which logic a test uses.\n\nStart with the most duplicated sequence in your suite (usually login or navigation), turn it into a sub‑flow, and watch the maintenance load drop.\n","https://blog-api.phomaapp.com/api/blog/posts/building-reusable-subflows-phoma-modular-test-automation/assets",1796035641346]