传载VBS实现自动化测试脚本

上一篇 / 下一篇  2010-04-03 18:57:43

纯VBS自动化测试脚本
Set ie = CreateObject("internetexplorer.application")
ie.Visible = true
'打开网页::3aTesting的BBS
ie.Navigate "www.3atesting.com/bbs"
'等待网页打开结束
delay(ie)
'获取QTP板块的链接,然后点击
Set linkAll=ie.document.getElementsByTagName("a")
Set searchLink=GetLink(linkAll,"QTP")
searchLink.click
delay(ie)

'随机取板块的某一个链接,并且点击
Set webTable=ie.Document.getElementsByTagName("Table")
Set webtableRows=webtable.item(1).getElementsByTagName("TR")
i=genRand(webtableRows.length)
Set tablelink=webtableRows.item(i).getElementsByTagName("a")
tablelink.item(1).click
delay(ie)

'获取帖子中iframe中的某一个对象,重新打开一个链接,并获取link对象,然后点击
Set iframes=ie.Document.getElementsByTagName("iframe")
i=genRand(iframes.length)
ie.Navigate iframes.item(i).src
delay(ie)
Set googlelink=ie.Document.getElementsByTagName("a")
googlelink.item(0).click
'MsgBox tablelink.length
'ie.Document.parentwindow.close
ie.Quit
Set googlelink=Nothing
Set iframes=Nothing
Set webtableRows=Nothing
Set webTable=Nothing
Set searchLink=Nothing
Set linkAll=Nothing
Set ie=Nothing

Function GetLink(objects,name)
For Each obj In objects
  tmp=obj.innertext
  'MsgBox tmp
  If Len(tmp)>0 Then
    If RegExpTest(obj.innertext,name) Then
       Set GetLink=obj
       Exit For
    End If
  End If
Next
End Function

Function RegExpTest(patrn, strng)
 Dim regEx, retVal            ' Create variable.
 Set regEx = New RegExp         ' Create regular expression.
 regEx.Pattern = patrn         ' Set pattern.
 regEx.IgnoreCase = False      ' Set case sensitivity.
 retVal = regEx.Test(strng)      ' Execute the search test.
 RegExpTest=retVal
End Function

Sub delay(obj)
 Do
   WScript.Sleep 5
 Loop Until CInt(obj.readyState)=4
' MsgBox CInt(obj.readyState)
End Sub

Function genRand(count)
genRand=Int(Rnd() * count)
End Function

TAG:

 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 9284
  • 日志数: 22
  • 建立时间: 2010-01-16
  • 更新时间: 2010-11-08

RSS订阅

Open Toolbar