我想知道是否有人知道我可以在使用 Appium for android 移动设备运行自动化测试时获取 logcat 的方法。我正在使用 Java,并且在 Windows 环境中。
有什么想法吗?谢谢!!
最佳答案
你可以使用这个实现:
List<LogEntry> logEntries = driver.manage().logs().get("logcat").getAll();
退出驱动程序之前。然后只需将列表打印到外部文件即可。
该方法看起来像这样:
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.");
}
}
关于java - Appium如何获取adb logcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28557828/