All posts

Debugging Flaky Broma Browser Automations

Debugging Flaky Broma Browser Automations

Why Flaky Automations Fail

Automation that works one day and breaks the next wastes valuable time for operations staff, e‑commerce sellers, marketers, and QA teams. When a flow fails, the task is delayed, data becomes outdated, and manual re‑entry is required. Reliable automation is essential for maintaining efficiency and data quality.

Common Causes of Flakiness

  • Dynamic page changes – new element IDs, class names, or DOM structure after a redesign.
  • Timing issues – waiting too long or too short for an element to appear.
  • Selector fragility – relying on generic class names that change frequently.
  • Hidden or conditional elements – elements that appear only after a hover, scroll, or after a network request.
  • Network latency – slow page loads cause the next step to run before the page is ready.
  • Pop‑ups and overlays – consent banners or notifications that block the target element.
  • Race conditions – multiple steps trying to interact with the same element simultaneously.

Step‑by‑Step Debugging Process

  1. Reproduce the failure manually

    • Open the target page in a regular browser.
    • Run the flow (or a single step) and note exactly where it stops.
    • Take a screenshot or record the URL and the element that should be clicked.
  2. Inspect the element

    • Use the browser’s developer tools (F12) to locate the element.
    • Observe its attributes: id, class, data- attributes, aria-label, etc.
    • Check whether the selector you use in Broma matches the current markup.
  3. Verify timing

    • Replace generic "wait 5 seconds" with a precise wait for the element to become visible or clickable.
    • Example in Broma’s custom JavaScript field:
    // Wait until the price element is visible
    await page.waitForSelector("xpath=//*[@data-product-price]", { visible: true });
    
    • If the element appears after an AJAX call, add a wait for network idle or for a specific network request.
  4. Check selector robustness

    • Prefer attributes that are less likely to change, such as data-test-id, name, or aria-label.
    • Avoid using auto‑generated class names like class="btn-1234".
    • If the page has multiple similar elements, use a relative XPath that anchors to a stable parent.
  5. Use Broma’s debug logs

    • Enable "Show detailed steps" in the workflow settings.
    • Run the flow and watch each action: which selector was used, what value was extracted, whether a click succeeded.
    • Note any warnings about element not found or stale reference.
  6. Insert logging statements

    • Add a "Log text" step that prints the current URL, the element’s text, or the result of a JavaScript expression.
    • Example:
    // Log the price after extraction
    console.log('Current price:', priceElement[0].innerText.trim());
    
    • The log appears in the run history, making it easy to see what went wrong.
  7. Test in isolation

    • Create a new temporary flow that contains only the problematic step.
    • Run it repeatedly to confirm whether the step itself is reliable.
    • If it fails alone, the issue is likely with the element or timing; if it succeeds, the problem may be a later step that depends on it.
  8. Fix and re‑run

    • Update the selector or add the appropriate wait.
    • Re‑execute the full flow and verify that it completes without errors.
    • Record the change in a version‑controlled file (e.g., a JSON export) for future reference.

Practical Tips for Robust Flows

  • Prefer stable attributes – look for data- attributes, ids that are unlikely to change, or semantic aria- labels.
  • Limit the use of fixed time waits – they mask underlying timing problems; use element‑visible checks instead.
  • Create a selector library – store commonly used selectors in a text file or a dedicated profile note; reuse them across multiple flows.
  • Run flows in isolated profiles – each profile keeps its own cookies, extensions, and proxy settings, preventing cross‑task contamination.
  • Schedule nightly runs with fresh profiles – this catches drift caused by site updates that occur during the day.
  • Maintain a smoke‑test flow – a lightweight flow that performs the core actions (open page, click, verify element) before the full scheduled run.

Real‑World Example: Price‑Monitoring Flow

A marketer set up a Broma flow to check the price of a competitor’s product every hour. The flow used the selector class="price-new" to read the price.

What broke?

After a site redesign, the price element’s class changed to price-old, and the flow stopped logging any value.

Debugging steps taken

  1. Reproduce – Open the product page, run the flow, and see that the step reports "Element not found".
  2. Inspect – In dev tools, locate the price element; it now has class="price-old" and a new attribute data-product-price.
  3. Verify timing – The element appears after the product images load, so a simple 2‑second wait was insufficient.
  4. Update selector – Change the selector to xpath=//*[@data-product-price] which is stable across redesigns.
  5. Add wait for network idle – Insert a step that waits until network activity drops below a threshold.
  6. Log the result – Add a "Log text" step that prints the extracted price.
  7. Test in isolation – Run only the price‑reading step; it now returns the correct value consistently.
  8. Fix and re‑run – Save the updated flow, enable the schedule, and confirm that the hourly run completes without errors.

Updated code snippet (Broma custom JavaScript)

// Extract price from the stable data attribute
const priceElement = await $x("//*[@data-product-price]");
if (priceElement.length > 0) {
  return priceElement[0].innerText.trim();
} else {
  throw new Error('Price element not found');
}

Best Practices to Prevent Future Flakiness

  • Version control – export each flow as a JSON file and store it in a Git repository. Tag releases when you make significant changes.
  • Descriptive step names – label each action with its purpose (e.g., "Wait for product price to appear") to make logs easier to read.
  • Smoke test – before scheduling a full run, execute a minimal flow that only opens the page and verifies the target element exists.
  • Weekly site review – browse the target pages weekly to spot UI changes early; update selectors proactively.
  • Use Broma’s profile manager – keep separate profiles for different tasks (e.g., one for price monitoring, another for form filling) to isolate cookies and extensions.

Conclusion

Flaky automations are a common pain point, but with a systematic debugging approach you can quickly pinpoint the cause, apply a durable fix, and prevent recurrence. By focusing on stable selectors, precise waits, thorough logging, and isolated testing, operations staff, e‑commerce sellers, marketers, and QA engineers can keep their Broma workflows reliable and efficient.