QTP-登录自动化测试

上一篇 / 下一篇  2016-06-12 11:13:05 / 个人分类:QTP自动化测试

本人最近在自学QTP自动化测试。根据QTP自带的测试登录例子编写了一个针对B/S应用的登录部分的测试脚本。以下是修改后的测试脚本。请大家提出宝贵的意见。谢谢!


Option Explicit

Dim url
url = "http://newtours.demoaut.com"

SystemUtil.Run "iexplore.exe",  url

Dim homeTitle
homeTitle = "Welcome: Mercury Tours"


Dim  excelUtil
Dim fileName,sheetName
Dim rowCount,rowNo
Dim userName,password,status
 
'读取Excel文件中的数据
fileName = "e:\login.xls"
sheetName="Global"
setExcelUtil excelUtil
rowCount = excelUtil.BuildRowHeading(fileName,sheetName)

For rowNo=0 To rowCount-1
  userName =  excelUtil.getCellData (rowNo,"Agent Name")
  password = excelUtil.getCellData (rowNo,"Password") 
  status = excelUtil.getCellData (rowNo,"Status")    

  With  Browser("title:="&homeTitle).Page("title:="&homeTitle)
       .WebEdit("name:=userName").Set userName
       .WebEdit("name:=password").Set password
      .Image("name:=login").Click
  End With

  If  Browser("title:=Sign-on: Mercury Tours").Exist(10) and status="Fail" Then
     Reporter.ReportEvent  micFail,"登录失败: ","登录失败,用户名:"&userName&",密码:"&password
     Browser("title:=Sign-on: Mercury Tours").Link("name:=Home").Click
  Elseif  Browser("title:=Find a Flight: Mercury Tours:").Exist(10)  and status="Pass" Then
     Reporter.ReportEvent PASS,"登录成功: ","成功"
     Browser("title:=Find a Flight: Mercury Tours:").Link("name:=Home").Click
  Else
     Reporter.ReportEvent Fail,"Login: ","Combination #  was not according to Excel file"   
  End If
  
Next


TAG:

 

评分:0

我来说两句

Open Toolbar