在多层架构的情况下,QTP 是否能够退出当前测试脚本和 运行 下一个测试脚本(通过主驱动程序脚本)?
will QTP be able to exit the current test script and run the next test script (through the master driver script) in case of multi-tier architecture?
下面是我们的 3 层 QTP 框架的设计。我的问题是
- 如果 Tier2 或 Tier3 出现错误,QTP 是否能够退出当前测试脚本和运行下一个测试脚本(通过主驱动程序脚本)?
- 我在下面写的主脚本代码有问题吗?主脚本执行单独的测试脚本并将结果状态、开始时间和结束时间写入字典,字典又写回 excel sheet
- 你们看到这个设计的其他 limitation/improvement 了吗?
请帮忙!
Master Driver Script – Tier1
Function Master ()
‘Take the contents of the excel sheet which stores the path of the test scrip to be executed, status, start time and end time in a record set
Do While Not oRecSet.EOF
dicResultSet.Add rCnt, CreateObject (“Scripting.Dictionary”)
For Each oField In oRecSet.Fields
dicResultSet (rCnt).Add oField.Name, oField.Value
‘Execute individual scripts
If oField.Name = “Path” Then
msQTPapp.Open oField.Value, True
Set qtTestScript = msQTPapp.Test
qtTestScript.Settings.Run.OnError = "NextStep"
strStartTime = Now
qtTestScript.Run
qtTestScript.Close
strEndTime = Now
End If
‘Write the status of the last run script in the dictionary object
If oField.Name = “Status” Then
dicResultSet (rCnt).Item (“Status”)=_ qtTestScript.LastRunResults.Status
End If
‘Write the start time of the last run script in the dictionary object
If oField.Name = “StartTime” Then
icResultSet (rCnt).Item (“StartTime”) = strStartTime
End If
‘Write the end time of the last run script in the dictionary object
If oField.Name = “EndTime” Then
dicResultSet (rCnt).Item (“EndTime”) = strEndTime
qtTestScript = Nothing
End If
Next
oRecSet.MoveNext
rCnt= rCnt+1
Loop
'Write the status, start time and end time of the individual test scripts in an excel sheet
'Close the rec set and connection
End Function
Test Script: Action – Tier2
‘Associate the individual test script with Environmental files, OR and other function library
Function Test1 ()
‘Call L1 from Function lib
‘Call L2 from Function lib
End Function
Function Library– Tier3
Function L1()
‘Actual task is getting done here
End Function
.
.
Function Ln()
‘Actual task is getting done here
End Function
我会专注于问题 1。如果您想问其他问题,请单独提出两个问题。但是,我担心它们会因为过于宽泛或主要基于意见而被关闭。
简短回答:是。
通过 AOM 调用的测试可以退出,例如使用 ExitTest
,并且 调用者确实可以继续执行另一个测试 。这与不显式退出的测试过程完全相同,只是执行它们的正常执行流程,然后优雅地终止。
即使测试由于 运行时间错误而中止,调用者脚本也会重新获得控制权,并且可以像测试成功后一样继续 运行。
下面是我们的 3 层 QTP 框架的设计。我的问题是
- 如果 Tier2 或 Tier3 出现错误,QTP 是否能够退出当前测试脚本和运行下一个测试脚本(通过主驱动程序脚本)?
- 我在下面写的主脚本代码有问题吗?主脚本执行单独的测试脚本并将结果状态、开始时间和结束时间写入字典,字典又写回 excel sheet
- 你们看到这个设计的其他 limitation/improvement 了吗? 请帮忙!
Master Driver Script – Tier1
Function Master ()
‘Take the contents of the excel sheet which stores the path of the test scrip to be executed, status, start time and end time in a record set
Do While Not oRecSet.EOF
dicResultSet.Add rCnt, CreateObject (“Scripting.Dictionary”)
For Each oField In oRecSet.Fields
dicResultSet (rCnt).Add oField.Name, oField.Value
‘Execute individual scripts
If oField.Name = “Path” Then
msQTPapp.Open oField.Value, True
Set qtTestScript = msQTPapp.Test
qtTestScript.Settings.Run.OnError = "NextStep"
strStartTime = Now
qtTestScript.Run
qtTestScript.Close
strEndTime = Now
End If
‘Write the status of the last run script in the dictionary object
If oField.Name = “Status” Then
dicResultSet (rCnt).Item (“Status”)=_ qtTestScript.LastRunResults.Status
End If
‘Write the start time of the last run script in the dictionary object
If oField.Name = “StartTime” Then
icResultSet (rCnt).Item (“StartTime”) = strStartTime
End If
‘Write the end time of the last run script in the dictionary object
If oField.Name = “EndTime” Then
dicResultSet (rCnt).Item (“EndTime”) = strEndTime
qtTestScript = Nothing
End If
Next
oRecSet.MoveNext
rCnt= rCnt+1
Loop
'Write the status, start time and end time of the individual test scripts in an excel sheet
'Close the rec set and connection
End Function
Test Script: Action – Tier2
‘Associate the individual test script with Environmental files, OR and other function library
Function Test1 ()
‘Call L1 from Function lib
‘Call L2 from Function lib
End Function
Function Library– Tier3
Function L1()
‘Actual task is getting done here
End Function
.
.
Function Ln()
‘Actual task is getting done here
End Function
我会专注于问题 1。如果您想问其他问题,请单独提出两个问题。但是,我担心它们会因为过于宽泛或主要基于意见而被关闭。
简短回答:是。
通过 AOM 调用的测试可以退出,例如使用 ExitTest
,并且 调用者确实可以继续执行另一个测试 。这与不显式退出的测试过程完全相同,只是执行它们的正常执行流程,然后优雅地终止。
即使测试由于 运行时间错误而中止,调用者脚本也会重新获得控制权,并且可以像测试成功后一样继续 运行。