一般来说编码很新,尤其是VB脚本。
我正在尝试在动作上启动计时器,并在页面加载时结束它。然后我想知道这个动作花了多少秒(这里的目标不到20秒)。
当我跑步时,它返回一个非常长的负数。 -3733642190秒。
这是代码。
'Choose the first record
PbWindow("w_mainframe").PbWindow("w_cash_detail").PbDataWindow("dw_search_main").SelectCell "#1","Contract_Party_Name"
PbWindow("w_mainframe").PbWindow("w_cash_detail").PbDataWindow("dw_search_main").ActivateCell "#1","Contract_Party_Name"
'start the timer
startTime = Now()
'Wait while the page load - up to 60 seconds.
While Not(PbWindow("w_mainframe").PbWindow("w_cash_detail").Exist(1)) and DateDiff("s", startTime, Now) <=60
Wait(1)
Wend
'If page did load, move on and test that the time was less than 20 seconds.
If PbWindow("w_mainframe").PbWindow("w_cash_detail").Exist Then
Reporter.ReportEvent micPass, "Invoice Items Page", "Invoice Items page loads from ACD search results successfully"
'stop the clock.
endTime = Now()
End If
'Time Comparison
If ABS(DateDiff("s", startTime, endTime)) <=20 Then
Reporter.ReportEvent micPass, "ACD page opened in" & " " & DateDiff("s", startTime, endTime) & " " & "second(s)", "The ACD opened this invoice in twenty seconds or less."
else Reporter.ReportEvent micFail, "ACD page opened in" & " " & DateDiff("s", startTime, endTime) & " " & "second(s)", "The ACD took longer than twenty seconds to open a normal Invoice."
End IF
答案 0 :(得分:0)
我将此作为答案添加,以便其他人可以看到原因和解决方案。
如果设置startTime
但endTime
设置为Empty
,则这是预期的行为。
修复方法是将其移到If
语句之外:
endTime = Now()