自动化测试中,经常遇到页面需要输入时间,而这个时间很多时候是当前时间之后某个范围之类才有效。我们采用数据驱动时如果采用绝对时间,则数据复用性就很差了,数据需要经常修改。所以采用相对时间
下面的函数用于获取相对时间
'------------------------------------------------------------------------
'获取以当前时间为参照的偏移时间
'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 |
(以上言论仅代表作者的个人观点,不代表51Testing观点)
版权声明:本文出自danmy的51Testing软件测试博客:http://www.51testing.com/?81672
原创作品,转载时请务必以超链接形式标明本文原始出处、作者信息和本声明,否则将追究法律责任。