测试页面表格增加对Call命令的适配

This commit is contained in:
2024-04-18 09:12:20 +08:00
parent 71ec6193ed
commit 240ce97c05
134 changed files with 14917 additions and 255 deletions

View File

@@ -218,7 +218,11 @@ Namespace UTSModule.Project
End Try
End If
_masterImg = ImageProcessor.ImageProcessor.GetBitmapImage(imgPath)
Try
_masterImg = ImageProcessor.ImageProcessor.GetBitmapImage(imgPath)
Catch ex As Exception
_masterImg = Nothing
End Try
End SyncLock
Return _masterImg

View File

@@ -28,7 +28,7 @@ Namespace UTSModule.Test.Command.SystemCommand
CommandReturn.RecordValue = String.Empty
CommandReturn.ExecuteResultTipString = $"未查询到[{_moduleName}]模块存在"
Else
Dim moduleResult As TestCommandReturn = tester.ExecuteModuleNode(rownode,_localVariable)
Dim moduleResult As TestCommandReturn = tester.ExecutePlan(rowNode, _localVariable)
CommandReturn.ExecuteResult = moduleResult.ExecuteResult
CommandReturn.RecordValue = String.Empty

View File

@@ -1,6 +1,8 @@
Imports System.Drawing
Imports System.Text
Imports FlexCell
Imports UTS_Core.UTSModule.Station
Imports UTS_Core.UTSModule.Station.StationTestPlan
Imports UTS_Core.UTSModule.Test.Command
Namespace UTSModule.Test
@@ -51,10 +53,18 @@ Namespace UTSModule.Test
Private _plan As StationTestPlan
''' <summary>内置模块入口集合</summary>
Private ReadOnly _testModules As New Dictionary(Of String, RowNode)
''' <summary>自定义模块下函数入口集合</summary>
Private ReadOnly _customModules As New Dictionary(Of String, RowNode)
Private ReadOnly _rowList As Dictionary(Of Integer, RowNode)
Private ReadOnly _nodeList As Dictionary(Of RowNode, Integer)
Private _callNodeList As New Dictionary(Of RowNode, List(Of Integer))
Private _callNodeUpdateCount As New Dictionary(Of RowNode, Integer)
Private ReadOnly _recodeRow As List(Of Integer)
Sub New()
@@ -113,19 +123,84 @@ Namespace UTSModule.Test
End Sub
''' <summary>
''' 获取指定变量名的变量值
''' </summary>
''' <param name="varName">变量名</param>
''' <param name="localVariable">调用模块时传入的局部变量</param>
''' <returns></returns>
Private Function ReplaceVar(varName As String, Optional localVariable As Dictionary(Of String, String) = Nothing) As String
'替换变量的逻辑顺序
'优先替换局部变量,也就是传进模块的变量
'其次使用用户变量,也就是记录入库的变量
'最后匹配系统变量,也就是预设带有特殊意义的字符串
If localVariable IsNot Nothing AndAlso localVariable.ContainsKey(varName) Then
Return localVariable(varName)
Else
Return varName
End If
End Function
Private Sub SearchRecordName(nodes As RowNodeCollection)
''' <summary>
''' 替换字符串中使用的变量,返回替换后的字符串
''' </summary>
''' <param name="sourceString">原字符串</param>
''' <param name="localVariable">调用模块时传入的局部变量</param>
''' <returns>替换后的字符串</returns>
Private Function ReplaceString(sourceString As String, Optional localVariable As Dictionary(Of String, String) = Nothing) As String
Dim strBuilder As New StringBuilder
Dim varName As New StringBuilder
Dim findVar As Boolean
For Each c As Char In sourceString
If c = "{"c Then
If findVar Then
findVar = False
strBuilder.Append("{")
Else
findVar = True
End If
ElseIf c = "}"c Then
If findVar Then
strBuilder.Append(ReplaceVar(varName.ToString() localVariable))
varName.Clear()
findVar = False
Else
strBuilder.Append("}")
End If
Else
If findVar Then
varName.Append(c)
Else
strBuilder.Append(c)
End If
End If
Next
Return strBuilder.ToString
End Function
Private Sub SearchRecordName(nodes As RowNodeCollection, Optional isCallNode As Boolean = False, Optional localVariable As Dictionary(Of String, String) = Nothing)
For Each node As RowNode In nodes
If node.Action = False Then Continue For
_grd.AddItem("")
Dim row As Integer = _grd.Rows - 1
_grd.Cell(row, ColNames.Record).Text = node.RecordName
_grd.Cell(row, ColNames.Description).Text = node.Description
_grd.Cell(row, ColNames.Record).Text = ReplaceString(node.RecordName, localVariable) '替换记录名称中变量
_grd.Cell(row, ColNames.Description).Text = ReplaceString(node.Description, localVariable)
_rowList.Add(row, node)
_nodeList.Add(node, row)
If isCallNode Then
If _callNodeList.ContainsKey(node) Then
_callNodeList(node).Add(row)
Else
_callNodeList.Add(node, New List(Of Integer) From {row})
End If
Else
_rowList.Add(row, node)
_nodeList.Add(node, row)
End If
If node.SaveToDb Then
_recodeRow.Add(row)
@@ -138,9 +213,82 @@ Namespace UTSModule.Test
If node.RowNodes.Count > 0 Then
SearchRecordName(node.RowNodes)
End If
'如果为Call命令则添加被调用模块下内容
If node.RowType = RowNode.RowTypeEnum.Flow AndAlso node.Command = "Call" Then
Dim moduleName As String = node.Parameters(0).Value
Dim varNames() As String = node.Parameters(1).Value.Split(":"c)
Dim varValues() As String = node.Parameters(2).Value.Split(":"c)
Dim variable As New Dictionary(Of String, String)
For i As Integer = 0 To varNames.Count - 1
variable.Add(varNames(i), varValues(i))
Next
Dim moduleNode As RowNode = GetModule(moduleName)
SearchRecordName(moduleNode.RowNodes, True, variable)
End If
Next
End Sub
''' <summary>
''' 更新测试模块入库
''' </summary>
Private Sub UpdateTestModule(rowNodes As RowNodeCollection)
_testModules.Clear()
GetTestModule(_testModules, rowNodes)
End Sub
''' <summary>
''' 获取执行行节点集合中测试模块入口,并存储至内部模块入口集合
''' </summary>
''' <param name="modules">存储测试模块入口集合</param>
''' <param name="nodes">行节点集合</param>
Private Sub GetTestModule(modules As Dictionary(Of String, RowNode), nodes As RowNodeCollection)
For Each node As RowNode In nodes
If node.RowType = RowNode.RowTypeEnum.FixedModule OrElse node.RowType = RowNode.RowTypeEnum.Module Then
If String.IsNullOrWhiteSpace(node.Label) Then Continue For
If modules.ContainsKey(node.Label) Then Continue For
modules.Add(node.Label, node)
End If
If node.Label = $"{FixedModuleEnum.Custom}" Then
_customModules.Clear()
GetTestModule(_customModules, node.RowNodes)
End If
Next
End Sub
''' <summary>
''' 获取固定模块节点
''' </summary>
''' <param name="name">固定模块名</param>
''' <returns></returns>
Public Function GetFixedModule(name As FixedModuleEnum) As RowNode
If _testModules.ContainsKey($"{name}") = False Then Return Nothing
Return _testModules($"{name}")
End Function
''' <summary>
''' 获取模块节点
''' </summary>
''' <param name="name">模块名</param>
''' <returns></returns>
Public Function GetModule(name As String) As RowNode
If _customModules.ContainsKey(name) Then
Return _customModules(name)
ElseIf _testModules.ContainsKey(name) Then
Return _testModules(name)
Else
Return Nothing
End If
'If _testModules.ContainsKey(name) = False Then Return Nothing
'Return _testModules(name)
End Function
Public Sub UpdateStepTestRecord()
With _grd
.AutoRedraw = False
@@ -169,13 +317,12 @@ Namespace UTSModule.Test
_nodeList.Clear()
_rowList.Clear()
_recodeRow.Clear()
_callNodeList.Clear()
If StationPlan IsNot Nothing Then
For Each node As RowNode In StationPlan.RowNodes
If String.Compare(node.Label, $"{StationTestPlan.FixedModuleEnum.Main}", True) = 0 Then
SearchRecordName(node.RowNodes)
Exit For
End If
Next
UpdateTestModule(StationPlan.RowNodes) '记录所有模块名
Dim mainNode As RowNode = GetFixedModule(FixedModuleEnum.Main)
SearchRecordName(mainNode.RowNodes) '添加Main模块下节点遇见Call命令则展开被调用的模块
End If
.AutoRedraw = True
@@ -211,13 +358,12 @@ Namespace UTSModule.Test
_nodeList.Clear()
_rowList.Clear()
_recodeRow.Clear()
If plan IsNot Nothing Then
For Each node As RowNode In plan.RowNodes
If String.Compare(node.Label, $"{StationTestPlan.FixedModuleEnum.Main}", True) = 0 Then
SearchRecordName(node.RowNodes)
Exit For
End If
Next
_callNodeList.Clear()
If StationPlan IsNot Nothing Then
UpdateTestModule(StationPlan.RowNodes) '记录所有模块名
Dim mainNode As RowNode = GetFixedModule(FixedModuleEnum.Main)
SearchRecordName(mainNode.RowNodes) '添加Main模块下节点遇见Call命令则展开被调用的模块
End If
.AutoRedraw = True
@@ -231,8 +377,19 @@ Namespace UTSModule.Test
''' <param name="node">当前测试节点</param>
''' <returns></returns>
Public Function GetRowByNode(node As RowNode) As Integer
If _nodeList.ContainsKey(node) = False Then Return 0
Return _nodeList(node)
Dim row As Integer = 0
If _nodeList.ContainsKey(node) Then
row = _nodeList(node)
ElseIf _callNodeList.ContainsKey(node) Then
If _callNodeUpdateCount.ContainsKey(node) Then
_callNodeUpdateCount(node) += 1
Else
_callNodeUpdateCount.Add(node, 0)
End If
row = _callNodeList(node)(_callNodeUpdateCount(node))
End If
Return row
End Function
@@ -319,6 +476,7 @@ Namespace UTSModule.Test
Public Sub ClearRecode()
If _grd Is Nothing Then Return
_callNodeUpdateCount.Clear()
For row As Integer = 1 To _grd.Rows - 1
_grd.Cell(row, ColNames.Elapsed).Text = ""