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<String[]> firstsheet = new ArrayList<String[]>();
// 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<String[]> secondsheet = new ArrayList<String[]>();
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<Integer, List<String[]>> report = new HashMap<Integer, List<String[]>>();
report.put(1, firstsheet); // first sheet data
report.put(2, secondsheet); // second sheet data
Excel.writeXlsx(report); // write report to Excel fileThe 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
