QTP中时间的处理-自动化测试
更新时间:2022-05-23 09:27:29 作者:多测师 浏览:166
自动化测试中,经常遇到页面需要输入时间,而这个时间很多时候是当前时间之后某个范围之类才有效。我们采用数据驱动时如果采用绝对时间,则数据复用性就很差了,数据需要经常修改。所以采用相对时间。
下面的函数用于获取相对时间
'------------------------------------------------------------------------
'获取以当前时间为参照的偏移时间
'increTime: 偏移时间量,可使用负数 格式:day:hour:min:sec 如 1:3:8:23
'------------------------------------------------------------------------
Public Function GetTime(byval increTime)
Dim y,m,d,h,n,s,timeArray
timeArray = split(increTime,":",-1,1)
d= timeArray(0)
h= timeArray(1)
n= timeArray(2)
s= timeArray(3)
GetTime = dateadd("d",d,now)
GetTime = dateadd("h",h,GetTime)
GetTime = dateadd("n",n,GetTime)
GetTime = dateadd("s",s,GetTime)
' change to GE Time type
Dim dateArr,timeArr
timeArray = split(GetTime," ",-1,1)
dateArr = split(timeArray(0),"-",-1,1)
y = dateArr(0)
m = ExpandByZero("L", dateArr(1),2)
d = ExpandByZero("L", dateArr(2),2)
timeArr = split(timeArray(1),":",-1,1)
h = ExpandByZero("L", timeArr(0),2)
n = ExpandByZero("L", timeArr(1),2)
s = ExpandByZero("L", timeArr(2),2)
GetTime = y & "-" & m & "-" & d & " " & h & ":" & n & ":" & s
End Function
'------------------------------------------------------------------------
'以0扩展当前字符串
'way: 扩展方式 L-左扩,R-右扩
'OrigStr: 原字符串
'HopeLen: 扩展后字符长度
'------------------------------------------------------------------------
Public Function ExpandByZero(byval way,byval OrigStr,byval HopeLen)
Dim i,ZeroStr
ZeroStr = ""
For i =1 to HopeLen - len(OrigStr)
ZeroStr = ZeroStr & "0"
Next
If way = "L" Then
ExpandByZero = ZeroStr & OrigStr
elseif way = "R" Then
ExpandByZero = OrigStr & ZeroStr
else
Exit Function
End If
End Function
以上内容为大家介绍了自动化测试中的QTP中时间的处理,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/