c# - 将 Appium 测试结果记录到控制台

标签 c# testing logging appium appium-desktop

Appium 不会将测试结果(UI 测试的,使用 adb 模拟器执行)记录到调试输出 (Deug.WriteLine)。

根据文档,可以使用以下行获取测试日志

ILogs logs = driver.Manage().Logs;

但是,Appium 有不同的日志类型:

  • 浏览器
  • 客户
  • 司机
  • 分析器
  • 服务器

我使用以下代码尝试了每种日志类型。但是通过执行我没有得到任何结果并且测试将(我放置代码的地方)失败。有人能解决这个问题吗?

ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Browser);
//  ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Client);
//  ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Driver);
//  ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Profiler);
//  ReadOnlyCollection<LogEntry> logs = _driver.Manage().Logs.GetLog(LogType.Server);

foreach (var log in logs)
{
    Debug.WriteLine("Time: " + log.Timestamp);
    Debug.WriteLine("Message: " + log.Message);
    Debug.WriteLine("Level: " + log.Level);
}

最佳答案

我只是想明白。

  1. 先看看这篇文章 relaxed Security AppiumService

  2. 获取日志类型

        IReadOnlyCollection<string> logTypes = driver.Manage().Logs.AvailableLogTypes;
        foreach (string logType in logTypes)
        {
            Console.WriteLine(logType);
            //logcat
            //bugreport
            //server
        }
    
  3. 打印日志

    public static void PrintLogs(string logType)
    {
        try
        {
            ILogs _logs = driver.Manage().Logs;
            var browserLogs = _logs.GetLog(logType);
            if (browserLogs.Count > 0)
            {
                foreach (var log in browserLogs)
                {
                    //log the message in a file
                    Console.WriteLine(log);
                }
            }
        }
        catch(Exception e)
        {
            //There are no log types present
            Console.WriteLine(e.ToString());
        }
    

Picture : C# Console Print appium log

关于c# - 将 Appium 测试结果记录到控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55351974/

相关文章:

c# - 对 WCF 服务的身份验证未使用 SetAuthCookie 和完整的 .net 客户端维护,但可与 silverlight 一起使用

c# - 我怎样才能排序但在底部放零?

testing - 带有 emberjs 的 CI

testing - 可扩展性与负载或性能测试究竟有何不同?

Magento 中的 JavaScript 控制台日志

c# - 我是否只需要在 Mock 对象上显式设置预期的返回值?

python - 使用 mock.patch 给我 AttributeError ("<module ' 包 1'' > 没有属性 'myfunc' “?

MYSQL,毫秒日志记录,操作系统 :windows 2012, 深度问题

php - 使用 echo 或 Die 进行调试和记录

c# - 从线程更新数据绑定(bind)数据表是否安全?