QTP中时间的处理

发表于:2010-1-22 17:53

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:danmy    来源:51Testing软件测试博客

  自动化测试中,经常遇到页面需要输入时间,而这个时间很多时候是当前时间之后某个范围之类才有效。我们采用数据驱动时如果采用绝对时间,则数据复用性就很差了,数据需要经常修改。所以采用相对时间

  下面的函数用于获取相对时间

  '------------------------------------------------------------------------

  '获取以当前时间为参照的偏移时间

  '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

原创作品,转载时请务必以超链接形式标明本文原始出处、作者信息和本声明,否则将追究法律责任。

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号