从现在开始,每天一点点……

QTP使用Excel参数化

上一篇 / 下一篇  2012-03-07 14:58:48 / 个人分类:QTP学习

1.创建一个文件在D:\TestFile.xls


2.编写下面的代码
Dim  xlApp    'Excel Application Automation Object Reference
Dim xlBook  'Reference to the workbook located in D:\
Dim xlSheet 'Reference to Sheet1
Dim iRow, sUserName, sPassword
Const iUserNameCol = 1
Const iPasswordCol = 2

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\TestFile.xls")
Set xlSheet = xlBook.Worksheets("Sheet1")

'SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com"

For iRow = 2 to xlSheet.UsedRange.Rows.Count
    sUserName = xlSheet.Rows(iRow).Columns(iUserNameCol).Value
    sPassword = xlSheet.Rows(iRow).Columns(iPasswordCol).Value
    With Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours")
        .WebEdit("name:=userName").Set  sUserName
        .WebEdit("name:=password").Set sPassword
        .Image("name:=login").Click
    End With
    If Browser("title:=Find a Flight: Mercury Tours:").Exist(15) Then
        Browser("title:=Find a Flight: Mercury Tours:").Link("text:=Home").Click
        Reporter.ReportEvent micPass,"Iteration " &iRow-1,"UserName:"&sUserName& "is valid"
    Else
        Reporter.ReportEvent micFail,"Iteration " &iRow-1,"UserName:"&sUserName& "is invalid"
        Browser("title:=Sign-on: Mercury Tours", "index:=0").Link("namet:=SIGN-ON").Click
    End If
Next
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing


TAG:

 

评分:0

我来说两句

日历

« 2024-03-19  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 11811
  • 日志数: 53
  • 书签数: 4
  • 建立时间: 2006-12-11
  • 更新时间: 2012-05-31

RSS订阅

Open Toolbar