测试报告导出
This commit is contained in:
@@ -3,6 +3,8 @@ using UIShare.PubEvent;
|
||||
using Common.Tools;
|
||||
using Logger;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Model.Entity;
|
||||
using ORM;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -42,7 +44,7 @@ namespace UIShare
|
||||
/// <summary>标记是否已被注销,执行方法据此安全退出</summary>
|
||||
private volatile bool _disposed = false;
|
||||
|
||||
private Guid TestRoundID;
|
||||
public Guid TestRoundID;
|
||||
public StepRunning(ScopedContext ScopedContext, SystemConfig systemConfig,IEventAggregator eventAggregator, DeviceManager deviceManager)
|
||||
{
|
||||
_scopedContext = ScopedContext;
|
||||
@@ -114,6 +116,7 @@ namespace UIShare
|
||||
step.CurrentLoopCount = context.LoopCount;
|
||||
LoggerHelper.InfoWithNotify(_systemConfig.Title, $"循环开始,共{context.LoopCount}次", depth);
|
||||
index++;
|
||||
SaveStepRecord(step, depth, true);
|
||||
}
|
||||
|
||||
// 处理循环结束
|
||||
@@ -124,6 +127,7 @@ namespace UIShare
|
||||
LoggerHelper.ErrorWithNotify(_systemConfig.Title, "未匹配的循环结束指令", depth: depth);
|
||||
step.Result = 2;
|
||||
index++;
|
||||
SaveStepRecord(step, depth, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -138,6 +142,7 @@ namespace UIShare
|
||||
// 继续循环:跳转到循环开始后的第一条指令
|
||||
index = context.StartIndex + 1;
|
||||
LoggerHelper.InfoWithNotify(_systemConfig.Title, $"循环第{context.CurrentLoop}次结束,跳回开始,剩余{context.LoopCount - context.CurrentLoop}次", depth);
|
||||
SaveStepRecord(step, depth, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -154,6 +159,7 @@ namespace UIShare
|
||||
program.ErrorStepCollection.First(x => x.ID == step.LoopStartStepId).Result = 1;
|
||||
loopStopwatchStack.Pop();
|
||||
}
|
||||
SaveStepRecord(step, depth, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +218,7 @@ namespace UIShare
|
||||
stepStopwatch.Stop();
|
||||
step.RunTime = (int)stepStopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
SaveStepRecord(step, depth, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +291,7 @@ namespace UIShare
|
||||
step.CurrentLoopCount = context.LoopCount;
|
||||
LoggerHelper.InfoWithNotify(_systemConfig.Title, $"循环开始({step.Name}),共{context.LoopCount}次", depth);
|
||||
index++;
|
||||
SaveStepRecord(step, depth, false);
|
||||
}
|
||||
|
||||
// 处理循环结束
|
||||
@@ -294,6 +302,7 @@ namespace UIShare
|
||||
LoggerHelper.ErrorWithNotify(_systemConfig.Title, "未匹配的循环结束指令", depth:depth);
|
||||
step.Result = 2;
|
||||
index++;
|
||||
SaveStepRecord(step, depth, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -308,6 +317,7 @@ namespace UIShare
|
||||
// 继续循环:跳转到循环开始后的第一条指令
|
||||
index = context.StartIndex + 1;
|
||||
LoggerHelper.InfoWithNotify(_systemConfig.Title, $"循环第{context.CurrentLoop}次结束,跳回开始,剩余{context.LoopCount - context.CurrentLoop}次", depth);
|
||||
SaveStepRecord(step, depth, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -324,6 +334,7 @@ namespace UIShare
|
||||
program.StepCollection.First(x => x.ID == step.LoopStartStepId).Result = 1;
|
||||
loopStopwatchStack.Pop();
|
||||
}
|
||||
SaveStepRecord(step, depth, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +400,7 @@ namespace UIShare
|
||||
_scopedContext.SingleStep = false;
|
||||
_eventAggregator.GetEvent<RunSingalCompletedEvent>().Publish("Play");
|
||||
}
|
||||
SaveStepRecord(step, depth, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,6 +681,56 @@ namespace UIShare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将单个步骤的执行结果保存到数据库(测试报告)。
|
||||
/// 同一次运行的所有步骤共享 TestRoundID,导出时按此 Guid 查询。
|
||||
/// </summary>
|
||||
private void SaveStepRecord(StepVM step, int depth, bool isErrorStep)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取输出参数值
|
||||
string? outputValue = null;
|
||||
if (step.Method != null)
|
||||
{
|
||||
var outputParam = step.Method.Parameters.FirstOrDefault(p => p.Category == ParameterCategory.Output);
|
||||
if (outputParam?.Value != null)
|
||||
outputValue = outputParam.Value.ToString();
|
||||
}
|
||||
|
||||
var entity = new TestReportEntity
|
||||
{
|
||||
TestRoundId = TestRoundID,
|
||||
Scope = _systemConfig.Title,
|
||||
StepIndex = step.Index,
|
||||
StepName = step.Name ?? "",
|
||||
StepType = step.StepType ?? "普通步骤",
|
||||
MethodName = step.Method?.Name,
|
||||
MethodFullName = step.Method?.FullName,
|
||||
Result = step.Result switch
|
||||
{
|
||||
-1 => "未执行",
|
||||
0 => "执行中",
|
||||
1 => "成功",
|
||||
2 => "失败",
|
||||
_ => "未知"
|
||||
},
|
||||
RunTimeMs = step.RunTime,
|
||||
OutputValue = outputValue,
|
||||
Depth = depth,
|
||||
IsErrorStep = isErrorStep,
|
||||
LoopRemaining = step.CurrentLoopCount,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
|
||||
SqlSugarContext.DbContext.Insertable(entity).ExecuteCommand();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerHelper.Error($"保存步骤记录失败 [{step.Index}]: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetAllStepStatus(ObservableCollection<StepVM> StepCollection)
|
||||
{
|
||||
foreach (var step in StepCollection)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<ProjectReference Include="..\Common\Common.csproj" />
|
||||
<ProjectReference Include="..\DeviceCommand\DeviceCommand.csproj" />
|
||||
<ProjectReference Include="..\Logger\Logger.csproj" />
|
||||
<ProjectReference Include="..\ORM\ORM.csproj" />
|
||||
<ProjectReference Include="..\ZLGUSBCANFD\ZLGUSBCANFD.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user