Appium如何获取adb logcat [英] Appium how to get adb logcat
本文介绍了Appium如何获取adb logcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有人知道我可以在使用 Appium for android 移动设备运行自动化测试时获取 logcat 的方法.我正在使用 Java,并且在 Windows 环境中.
I was wondering if anybody knows a way that i can get the logcat while running automated tests using Appium for android mobile device. I'm using Java and I'm in a windows environment.
有什么想法吗?谢谢!!
Any ideas? Thanks!!
推荐答案
你可以使用这个实现:
List<LogEntry> logEntries = driver.manage().logs().get("logcat").getAll();
在退出驱动程序之前.然后只需将列表打印到外部文件.
Before quitting the driver. Then just print the list to an external file.
该方法看起来像这样:
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.");
}
}
这篇关于Appium如何获取adb logcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文