Short answer: when a nightly run comes back with 40 red tests, don't open the first one. Group the failures by their error message first, after stripping the parts that change on every run (session ids, timeouts, coordinates, timestamps). Forty failures usually collapse into a handful of reasons. Then label each test from its history (new failure, flaky, never passed), and you know which group to open first and what to do with it. Below is a 75-line Python script that does this on JUnit XML, and what to do with each kind of group.

Why reading failures one by one doesn't scale

The usual morning goes like this. Someone opens the report, clicks the first red test, reads a stack trace, opens the screenshot, decides it's the new checkout button, and moves to test two. Test two is the same thing. So is test three. Around test twelve they stop reading and start guessing, and that's when the one test that failed for a different reason gets skipped.

The failures were never 40 problems. They were 40 symptoms of three or four. The work is to find those few before anyone debugs anything.

Step 1: make two failures of the same step look the same

Two runs of one broken step rarely produce the same error text. Compare:

NoSuchElementError: An element could not be located on the page using the given search parameters (accessibility id: 'Checkout'). Waited 10s. Session id: 3f9c1a... NoSuchElementError: An element could not be located on the page using the given search parameters (accessibility id: 'Checkout'). Waited 12s. Session id: 81be04... 

Same reason, different strings. If you group on the raw message, every failure is its own group and you've gained nothing. So first normalize: replace everything that varies per run with a placeholder, and keep everything that says why: the words, the locator, short quoted labels.

What to replace:

Noise Example Becomes
Session ids, element handles, hashes 3f9c1a7e... <id>
Durations Waited 12s, 500ms <time>
Timestamps 2026-12-06T03:14:09Z <timestamp>
Tap coordinates (540, 1200) <xy>
Other numbers expected '$84.00' <n>
Stack frames and driver banners at io.appium..., Build info: ... dropped

Keep the locator. accessibility id: 'Checkout' and accessibility id: 'Pay' are two different problems even though the error class is the same.

Step 2: label each test from its history

A group tells you what happened. History tells you how worried to be. You need only three labels:

  • New failure: it passed in the previous run. Something changed since yesterday: the app, the test, or the environment. Start here.
  • Flaky: it passed at least once in its last 10 runs. A real problem, but not today's.
  • Never passed: it has failed every run, three runs or more. Probably a test that was never finished, or a feature that never worked. Don't let it hide today's new failures.

A group of 22 new failures with the same locator is a very different morning from a group of 22 flaky tests.

The script

Point it at a folder with one JUnit XML file per run (Appium, Selenium, pytest, JUnit, TestNG and most CI tools can write one). Files sort oldest to newest by name, so name them by date or build number.

#!/usr/bin/env python3 """Group a run's failed tests by reason and label each one from its history. Usage: python3 group_failures.py runs/ (one JUnit XML file per run, sorted oldest to newest) """ import re import sys from collections import defaultdict from pathlib import Path import xml.etree.ElementTree as ET # Noise that differs between two runs of the same broken step. NOISE = [ (re.compile(r"\s*\b(session id|build info|driver info):.*$", re.I), ""), # driver tail on the same line (re.compile(r"\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b", re.I), "<id>"), (re.compile(r"\b(?=[0-9a-f]*\d)[0-9a-f]{8,}\b", re.I), "<id>"), # session ids, element handles (re.compile(r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?Z?"), "<timestamp>"), (re.compile(r"\b\d+(\.\d+)?\s?(ms|s|seconds?|min)\b", re.I), "<time>"), # "waited 10s" vs "waited 12s" (re.compile(r"[(\[]\s*-?\d+\s*,\s*-?\d+\s*[)\]]"), "<xy>"), # tap coordinates (re.compile(r"\b\d+(\.\d+)?\b"), "<n>"), ] def normalize(message: str) -> str: head = [] for line in message.strip().splitlines(): if re.match(r"\s*(at\s|session id:|build info:|system info:|driver info:)", line, re.I): break # the stack and driver banner say nothing about the reason head.append(line.strip()) text = " ".join(head) for pattern, placeholder in NOISE: text = pattern.sub(placeholder, text) return text[:300] def read_run(path: Path) -> dict: """test name -> None if it passed, else the failure message.""" results = {} for case in ET.parse(path).getroot().iter("testcase"): name = f'{case.get("classname", "")}.{case.get("name")}' failure = case.find("failure") if failure is None: failure = case.find("error") if case.find("skipped") is not None: continue results[name] = None if failure is None else (failure.get("message") or failure.text or "") return results def label(name: str, history: list) -> str: runs = [r[name] for r in history if name in r] # oldest to newest, this run last passed = [msg is None for msg in runs] if len(runs) >= 2 and passed[-2]: return "new failure" if any(passed[-10:]): return "flaky" if len(runs) >= 3 and not any(passed): return "never passed" return "failing" def main(folder: str) -> None: history = [read_run(p) for p in sorted(Path(folder).glob("*.xml"))] current = history[-1] groups = defaultdict(list) for name, message in current.items(): if message is not None: groups[normalize(message)].append(name) failed = sum(len(tests) for tests in groups.values()) print(f"{failed} failed tests, {len(groups)} reasons\n") for reason, tests in sorted(groups.items(), key=lambda g: -len(g[1])): print(f"[{len(tests)}] {reason}") for name in sorted(tests): print(f" {label(name, history):13} {name}") print() if __name__ == "__main__": main(sys.argv[1]) 

On a run where 40 tests failed, the output looks like this:

40 failed tests, 3 reasons [22] NoSuchElementError: ... (accessibility id: 'Checkout'). Waited <time>. new failure checkout.t00 ... flaky checkout.t12 [12] AssertionError: expected order total '$<n>' but was '$<n>' new failure checkout.t22 ... [6] NoSuchElementError: ... (accessibility id: 'Pay'). Waited <time> never passed checkout.t34 ... 

Three reasons instead of 40 problems, sorted by size, and you can see at a glance that the first two groups are new today.

Two limits worth knowing. Grouping on text alone will merge two assertions with the same message on different screens, so add the step name or screen to the key if you have it. And a message that embeds a long piece of data, like a whole order id in quotes, may need its own rule.

Step 3: route each group, not each test

Once failures are grouped, each group usually ends up on one of two paths. This is triage, not a diagnosis: the group tells you what happened, and a person still decides why.

The element wasn't on the screen. The test looked for Checkout and it wasn't there. Either the app changed on purpose (the button was renamed or moved) and the test needs the new locator, or the app is broken. Look at one screenshot from the group. If the button is there under another name, fix the locator once, in the shared step or page object, and the whole group goes green. If the screen shows an error instead, it's a bug.

A check failed. The step ran but the value was wrong: the order total was $0.00. That's usually a bug report, and one report covers the whole group. Attach one screenshot and the list of tests, not 12 tickets.

Then the labels decide the order: new failures first, then the rest of the groups, with flaky and never-passed tests kept out of today's list.

Doing it on RobotActions

We build RobotActions, a cloud of real Android and iOS devices for manual testing, automation and AI agents, and this is what our failure triage does for every run. Watch the 60-second walkthrough on YouTube: Failure triage on real devices.

  • Grouped as each run ends. For your own Appium or Selenium tests on our grid and for scriptless tests alike, failures are grouped by the same reason. For phone runs, the same locator missing on the same screen counts as one reason, with a screenshot.
  • Every failure analysed. You see the failing step, what the test looked for, a screenshot and what happened (the element wasn't on the screen, or a check failed), plus its history: "failed 3 of the last 10 runs", "fails only on this device".
  • History labels. New failure, flaky, never passed, and also failing in other suites for the same reason in the last 7 days.
  • Next steps from the group. On a failed coded run, a suggested locator with a copy button. On a failed scriptless test, Fix with AI opens a Debug-with-AI session on a real device. When the same failure shows up across tests, Update step in N tests opens the step for editing, and Ask AI agent to file a Jira bug hands the group to your AI agent to file.
  • Your agent reads it too, over MCP.

Try it

Try it free · No credit card required