Building Reusable Sub-Flows in Phoma for Modular Test Automation
Why sub‑flows matter
When 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:
- Maintenance burden – a UI change forces you to edit every copy.
- Inconsistent behavior – small variations creep in (different wait times, alternate selectors).
- Team friction – reviewers can’t tell whether a flow uses the canonical version.
Phoma 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.
Core concepts
| Concept | Description |
|---|---|
| Sub‑flow | A regular Phoma flow marked Reusable. It has its own start/end, variables, and can be invoked from any other flow. |
| 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. |
| 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. |
| Scope | Sub‑flows live in the same project as the calling flow, so they share the same device pool and credentials. |
Step‑by‑step: creating a reusable login sub‑flow
1. Build the atomic steps
- Open Phoma → New Flow → name it
Login_SubFlow. - Add the following steps (use the visual builder, no code):
- Wait for element – selector
resourceId:com.example.app:id/username_field - Type text – value
${username}(parameter) - Wait for element – selector
resourceId:com.example.app:id/password_field - Type text – value
${password}(parameter) - Tap – selector
resourceId:com.example.app:id/login_button - Wait for element – selector
resourceId:com.example.app:id/home_screen_marker(confirms success)
- Wait for element – selector
- In the flow settings, enable Reusable and add two input parameters:
username(string) andpassword(string). No output parameters are needed for this example.
2. Publish a version
- Click Publish → enter a version tag
v1.0-login. - Phoma stores the flow definition and the tag. You can later publish
v1.1-loginafter adjusting a wait time.
3. Call the sub‑flow from a test case
- Create a new flow
Smoke_Test_Home. - Add a Run Sub‑Flow step.
- In the step config:
- Sub‑flow → select
Login_SubFlow. - Version → choose Latest (or pin
v1.0-login). - Inputs → map
${testUser}→username,${testPass}→password.
- Sub‑flow → select
- Continue with the rest of the smoke test (e.g., navigate to settings, assert version).
4. Run and verify
- Execute
Smoke_Test_Homeon a single device. The run log shows the sub‑flow steps expanded under the Run Sub‑Flow node, making debugging transparent. - Change the login UI (e.g., new resource‑id). Edit
Login_SubFlow, publishv1.1-login. All callers using Latest automatically pick up the fix.
Parameter patterns for real‑world scenarios
Multiple environments
{
"env": "staging",
"username": "qa_user",
"password": "${secrets.staging_pwd}"
}
Pass env as an input; inside the sub‑flow use a Condition step to select the correct base URL or API endpoint.
Returning data to the caller
If 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.
Optional steps with defaults
Mark 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).
Version‑pinning strategy for teams
| Strategy | When to use | How to enforce |
|---|---|---|
| Always Latest | Fast‑moving prototypes, solo developers | Default in Phoma; no extra config. |
| Pin to tag | Regression suites that must stay stable | In each Run Sub‑Flow step, set Version to a specific tag (v1.0-login). |
| 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. |
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.
Organising sub‑flows in a project
- Folder convention – Phoma lets you create folders in the flow list. Use
subflows/auth,subflows/navigation,subflows/data-entry. - Naming – Prefix with domain:
auth_login,nav_open_settings,data_enter_profile. - Documentation – Add a Description field on each sub‑flow (Markdown supported). Example:
## auth_login Logs a user into the app. **Inputs**: `username`, `password` **Outputs**: `sessionToken` **Assumptions**: App is on the login screen. - 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.
Debugging a failing sub‑flow call
- Open the Run Log of the parent flow.
- Expand the Run Sub‑Flow node – you see every inner step with its own pass/fail status.
- 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.
- Re‑run the parent flow; it will automatically use the new version if set to Latest.
Example: end‑to‑end checkout test using three sub‑flows
Smoke_Test_Checkout
├─ Run Sub‑Flow: auth_login (v1.1-login)
├─ Run Sub‑Flow: nav_open_cart (v1.0-cart)
├─ Run Sub‑Flow: data_enter_shipping (v1.2-shipping)
├─ Tap: place_order_button
└─ Assert: order_confirmation_text
Each sub‑flow encapsulates a distinct UI area. When the shipping screen changes, only data_enter_shipping needs an update. The checkout test remains untouched.
Best‑practice checklist
- Single responsibility – a sub‑flow does one logical thing (login, navigate, fill form).
- Explicit parameters – avoid hidden globals; pass everything via inputs/outputs.
- Version tags on every publish – never rely on an unnamed “latest” in CI.
- Document assumptions – e.g., “app must be on home screen”.
- Test sub‑flows in isolation – run them alone on a clean device before integrating.
- Review changes with the team – use Phoma’s built‑in diff view when publishing a new tag.
Scaling to many devices
Because 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.
Summary
Reusable 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:
- Faster maintenance – one edit fixes dozens of tests.
- Predictable CI – pinned versions guarantee reproducibility.
- Team confidence – reviewers see exactly which logic a test uses.
Start with the most duplicated sequence in your suite (usually login or navigation), turn it into a sub‑flow, and watch the maintenance load drop.
