Appium如何获得adb logcat [英] Appium how to get adb logcat

查看:190
本文介绍了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.

任何想法?谢谢!!

推荐答案

您可以使用此实现:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆