Appium how to get adb logcat

I was wondering if anyone knows how I can get the logarithm during automated tests using Appium for an Android mobile device. I use Java and I am in a Windows environment.

Any ideas? Thank!!

+3
source share
3 answers

You can use this implementation:

List<LogEntry> logEntries = driver.manage().logs().get("logcat").getAll();

Before exiting the driver. Then just print the list to an external file.

The method will look something like this:

public static void captureLog(AppiumDriver driver, String testName)
    throws Exception {
    DateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH-mm-ss");
    Date today = Calendar.getInstance().getTime();
    String reportDate = df.format(today);
    String logPath = "C:\\automation_capture\\";
    log.info(driver.getSessionId() + ": Saving device log...");
    List<LogEntry> logEntries = driver.manage().logs().get("logcat").filter(Level.ALL);
    File logFile = new File(logPath + reportDate + "_" + testName + ".txt");
    PrintWriter log_file_writer = new PrintWriter(logFile);
    log_file_writer.println(logEntries );
    log_file_writer.flush();
    log.info(driver.getSessionId() + ": Saving device log - Done.");
    }
}
+9
source

But be careful! The .getTimestamp () function for a single LogEntry returns an invalid value

List<LogEntry> adbLogs = driver().manage().logs().get("logcat").filter(Level.ALL);
log.info("First timestamp: " + adbLogs.get(0).getTimestamp());
log.info("Last timestamp: " + adbLogs.get(adbLogs.size()-1).getTimestamp());

Output (it is a bit formatted):

First time stamp: 1,514,841,545,766

: 1 514 841 594 154

logcat:

1514841545767 01-01 19:39:48.570 bla-bla-bla-first-record

1514841594154 01-01 23:19:53.440 bla-bla-bla-last-record

+2

You can use:

Process process = Runtime.getRuntime().exec("//Users//.....//.....//android-sdk-macosx//platform-tools//adb logcat -d");
0
source

All Articles