Retry Failed Android UiAutomator Test Cases and Export Results to Excel
This article explains how to automatically rerun failed Android UiAutomator test cases, collect their results, and generate a detailed Excel report using Java code that handles both initial and retry executions.
When using Android UiAutomator for testing, flaky failures can occur due to slow page loads, network latency, or unexpected conditions; the author proposes a solution that automatically reruns failed test cases and records all results in an Excel report.
List firstsheet = new ArrayList (); // new list to store each test case result String[] title = {"编号","用例名","运行状态","错误信息","错误行Library","错误行Special","错误行Case","开始时间","结束时间"}; firstsheet.add(title); // add header row new RunHelper(jarname, "1"); // compile jar and push to device setMobileInputMethodToUtf(); // set input method to UTF-7 for (int i = 0; i < MethodList.size(); i++) { String[] result = execCmdAndReturnResult(jarname, "student.Case", MethodList.get(i), i); // run test case firstsheet.add(result); // store result } List secondsheet = new ArrayList (); secondsheet.add(title); // add header to second sheet for (int s = 0; s < firstsheet.size(); s++) { String[] result = firstsheet.get(s); // iterate each result if (!result[2].equals("运行成功")) { // if not successful String[] second = execCmdAndReturnResult(jarname, "student.Case", result[1], s); // rerun secondsheet.add(second); // add retry result } } Map > report = new HashMap >(); report.put(1, firstsheet); // first sheet data report.put(2, secondsheet); // second sheet data Excel.writeXlsx(report); // write report to Excel file
The author notes that the comments are a bit messy but hopes the provided code helps readers implement reliable test retries and generate comprehensive Excel reports.
FunTester
10k followers, 1k articles | completely useless
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.