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);
}
最佳答案
我只是想明白。
先看看这篇文章 relaxed Security AppiumService
获取日志类型
IReadOnlyCollection<string> logTypes = driver.Manage().Logs.AvailableLogTypes; foreach (string logType in logTypes) { Console.WriteLine(logType); //logcat //bugreport //server }
打印日志
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()); }
关于c# - 将 Appium 测试结果记录到控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55351974/