using AddInPlugin.Setting;
|
using OpenTap;
|
using OpenTap.Addin.Util;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Text;
|
|
namespace AddInPlugin
|
{
|
public class TxtReportListener : ReportListener
|
{
|
|
public TxtReportListener(string name) : base(name)
|
{
|
|
}
|
|
public override IResultListener CreateChild()
|
{
|
var res = new TxtReportListener($"{Name}_Child");
|
if (this.Root == null)
|
{
|
res.Root = this;
|
}
|
else
|
{
|
res.Root = this.Root;
|
}
|
return res;
|
}
|
|
private void WriteReport(string text)
|
{
|
string file = Path.Combine(StationSettings.Current.ReportPath,
|
$"{CurrentPlanRun.TestPlanName}_{CurrentPlanRun.StartTime.ToString("yyyyMMddHHmmssfff")}.txt");
|
using (var fs = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
|
using (var writer = new StreamWriter(fs, Encoding.UTF8))
|
{
|
writer.WriteLine(text);
|
writer.Flush();
|
}
|
}
|
|
protected override void PlanStarted()
|
{
|
lock (this)
|
{
|
WriteReport($"{CurrentPlanRun.TestPlanName} Start {CurrentPlanRun.StartTime:yyyy-MM-dd HH:mm:ss.fff}\r\n");
|
}
|
}
|
|
protected override void StepComplated(TestStepRun stepRun)
|
{
|
lock (this)
|
{
|
if (stepRun.Report != null)
|
{
|
string text = $"*********** {stepRun.TestStepPath} Start {stepRun.Report.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")} ***********\r\n";
|
text += $"Result: {stepRun.Verdict}\r\n";
|
text += $"Parameters: ----------\r\n";
|
var datas = new List<string[]>();
|
|
datas.Add(new string[] { "Name", "Type", "Value" });
|
foreach (var detail in stepRun.Report.Details)
|
{
|
datas.Add(new string[] { detail.Name, detail.Type, detail.Normal ? detail.Value : detail.Exception.Message });
|
}
|
text += ChineseTableExporter.ToString(3, datas);
|
|
text += $"-----------------------\r\n";
|
text += $"{stepRun.TestStepPath} End {stepRun.Report.EndTime.ToString("yyyy-MM-dd HH:mm:ss.fff")} \r\n";
|
|
WriteReport(text);
|
}
|
}
|
}
|
|
protected override void PlanComplated()
|
{
|
lock (this)
|
{
|
WriteReport($"{CurrentPlanRun.TestPlanName} End {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}\r\nResult: {CurrentPlanRun.Verdict}\r\n");
|
}
|
}
|
}
|
}
|