All posts

Build Reusable Broma Sub-Flows for Team Form Filling

Build Reusable Broma Sub-Flows for Team Form Filling

Why reusable sub‑flows matter

When several people automate the same web forms — checkout, signup, profile updates — copying steps into every flow creates maintenance nightmares. A single selector change forces you to edit dozens of flows. Sub‑flows solve this by letting you define a form‑filling routine once and call it from any parent flow.

What a sub‑flow is in Broma

A sub‑flow is a regular Broma flow that exposes input parameters. Other flows invoke it with the Call Flow step, passing values at runtime. Because the sub‑flow runs in the same browser profile, it inherits cookies, logins, and proxy settings automatically.

Benefits for a team

  • Consistency – every flow uses the exact same field order, validation, and error handling.
  • Single source of truth – fix a selector once; all callers benefit.
  • Faster onboarding – new members drop a Call Flow step instead of rebuilding the form logic.
  • Version control – export the sub‑flow JSON, store it in Git, and review changes like code.

Step‑by‑step: build an address sub‑flow

1. List the common fields

Typical address forms share these fields:

  • Full name
  • Street line 1
  • Street line 2 (optional)
  • City
  • State / province
  • Postal code
  • Country dropdown
  • Phone number

2. Create a new flow and add parameters

  1. In Broma, click New Flow → name it Subflow_AddressForm.
  2. Open the Variables panel and add the following Input variables (type Text unless noted):
    • fullName
    • street1
    • street2
    • city
    • state
    • postalCode
    • country (type Text; you’ll map to the dropdown value)
    • phone

3. Add steps with resilient selectors

Use the Select Element tool to pick each input. Prefer attributes that rarely change: name, data-testid, or aria-label. Example for the street line:

{
  "selector": "input[name='address_line1']",
  "action": "type",
  "value": "{{street1}}"
}

Repeat for each field. For the country dropdown, use a Select Option step with value: "{{country}}".

4. Clean and format data with JavaScript expressions

Phone numbers often arrive in various formats. Add a Run JavaScript step before typing the phone field:

// Normalize to digits only, then format as +1 (555) 123-4567
const raw = {{phone}};
const digits = raw.replace(/\D/g, '');
if (digits.length === 10) {
  return `+1 (${digits.slice(0,3)}) ${digits.slice(3,6)}-${digits.slice(6)}`;
}
return raw; // fallback

Assign the result to a temporary variable cleanPhone and type {{cleanPhone}} into the phone input.

5. Test the sub‑flow in isolation

  1. Open a test page that contains the address form (e.g., a staging checkout).
  2. Run the flow with sample values in the Run Flow dialog.
  3. Verify each field is filled correctly and the form submits without errors.

Calling the sub‑flow from parent flows

1. Add a Call Flow step

In any parent flow (e.g., Checkout_Guest, Signup_Newsletter), insert a Call Flow step.

  • Flow to call: Subflow_AddressForm
  • Parameter mapping:
    {
      "fullName": "{{customer.name}}",
      "street1": "{{customer.address.line1}}",
      "street2": "{{customer.address.line2}}",
      "city": "{{customer.address.city}}",
      "state": "{{customer.address.state}}",
      "postalCode": "{{customer.address.zip}}",
      "country": "{{customer.address.countryCode}}",
      "phone": "{{customer.phone}}"
    }
    

2. Pass data from CSV, API, or previous steps

If you batch‑process orders, loop over a CSV file and feed each row into the Call Flow step. The sub‑flow receives the exact values it expects.

Version control and sharing

  1. Export the sub‑flow: right‑click → Export Flow → save as Subflow_AddressForm.json.
  2. Commit the JSON to your team’s Git repo. Include a README.md that documents each input variable and expected format.
  3. When a selector changes, update the sub‑flow, commit, and ask teammates to pull the latest version.

Example: one sub‑flow, three parent flows

Parent flow Use case How it calls the sub‑flow
Checkout_Guest Guest checkout on Shopify Maps order‑summary variables to address fields
Signup_Newsletter Newsletter signup with optional address Passes only fullName, email, country; leaves address lines empty
Profile_Update User edits saved address Reads current profile data, sends to sub‑flow, then clicks Save

All three flows stay in sync because they share the same sub‑flow logic.

Common pitfalls and fixes

  • Parameter name mismatch – Broma validates at runtime; double‑check spelling in the Call Flow mapping.
  • Selector drift – If a site redesigns the form, update the selector in the sub‑flow once; all callers inherit the fix.
  • Optional fields – For fields like street2, guard the type step with a Branch step: if ({{street2}} !== "") { type … }.
  • Dropdown value vs. label – Ensure the country variable matches the dropdown’s value attribute, not the visible label.

Best‑practice checklist

  • Name sub‑flows with a Subflow_ prefix for easy discovery.
  • Document every input variable (type, example, required/optional).
  • Keep selectors anchored to stable attributes (name, data-testid).
  • Use JavaScript expressions for data cleaning, not multiple type steps.
  • Export and commit after every change; tag releases (e.g., v1.2.0).
  • Run a quick smoke test on a staging environment before merging.

Wrap up

Reusable sub‑flows turn repetitive form‑filling into a maintainable library. By defining the address logic once, exposing clear parameters, and calling it from any parent flow, your team reduces errors, speeds up new automations, and keeps all workflows aligned when a site changes. Start with a single high‑frequency form, promote it to a sub‑flow, and watch the maintenance burden drop across every project that touches that form.