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.

FunTester
FunTester
FunTester
Retry Failed Android UiAutomator Test Cases and Export Results to Excel

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 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaAndroid
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.