SystemUtil.Run "http://192.168.1.58:8080"
'以下两个变量,记录用户名、密码的输入情况
'0代表输入为空,1代表输入正确,2代表输入错误
Dim Udatainfo,Pdatainfo,warn
rowcount=DataTable.GetSheet("login").GetRowCount
Browser("畅贷网").Page("畅贷网").Link("登录").Click
For j = 1 To rowcount Step 1
DataTable.SetCurrentRow j
Browser("畅贷网").Page("畅贷网").Link("登录").Click
With Browser("畅贷网").Page("登录界面")
.WebEdit("用户名").Set DataTable("username","login")
.WebEdit("密码").Set DataTable("password","login")
End With
'检查用户名输入情况
If DataTable("username","login")=Environment("bgusername") Then
Udatainfo=1
ElseIf DataTable("username","login")="" Then
Udatainfo=0
else
Udatainfo=2
End If
'检查密码的输入情况
If DataTable("password","login")=Environment("bgpassword") Then
Pdatainfo=1
ElseIf DataTable("password","login")="" Then
Pdatainfo=0
else
Pdatainfo=2
End If
' Browser("畅贷网").Page("登录界面").WebElement("登 录").Click
' Call errormsg()
call login(Udatainfo,Pdatainfo,DataTable("username","login"),DataTable("password","login"))
Next
'判断登录是否正确
Function login(Udatainfo,Pdatainfo,user,password)
If (Udatainfo=0 and Pdatainfo=0) or (Udatainfo=2 and Pdatainfo=0) or (Udatainfo=1 and Pdatainfo=0) Then
Browser("畅贷网").Page("登录界面").WebElement("登 录").Click
call usenull(user,password)
End If
If Udatainfo=1 and Pdatainfo=1 Then
Browser("畅贷网").Page("登录界面").WebElement("登 录").Click
Call loginsuc(user,password)
Browser("畅贷网").Close
SystemUtil.Run "http://192.168.1.58:8080"
wait 3
End If
If (Udatainfo=0 and Pdatainfo=2) or (Udatainfo=0 and Pdatainfo=1) or (Udatainfo=2 and Pdatainfo=2) or (Udatainfo=2 and Pdatainfo=1) or (Udatainfo=1 and Pdatainfo=2) Then
Browser("畅贷网").Page("登录界面").WebElement("登 录").Click
Call errorUP(user,password)
End If
End Function
'登录成功的判断-----1
Sub loginsuc(user,password)
wait 3 @@ hightlight id_;_Browser("畅贷网").Page("我是借款人 - 51钱")_;_script infofile_;_ZIP::ssf1.xml_;_
If Browser("畅贷网").Page("我的账户界面").Exist Then
Reporter.ReportEvent micPass,"check if login sccessfully","Login successfully ! username:"&user&" and "&"passsword:"&password
else
Reporter.ReportEvent micFail,"check if login Fail","Login Fail ! username"&user&"passsword"&password
End If
End Sub
'用户名为空密码为空或用户名不空密码为空----2
Sub usenull(user,password)
warn=errormsg()
If warn="" Then
Reporter.ReportEvent micPass,"check if login Fail","用户名为空密码为空或用户名不空密码为空"
End If
End Sub
'错误的用户名和密码------3
Sub errorUP(user,password)
warn=errormsg()
If warn<>"" Then
Reporter.ReportEvent micPass,"check if login Fail",warn&"---用户名:"&user&" and 密码"&password
End If
End Sub
Function errormsg()
Set obj=Browser("畅贷网").Page("登录界面").Object
Set formObj=obj.getElementById("logOnForm")
set divObj=formObj.getElementsByTagName("div")
For i = 0 To divObj.length-1 Step 1
If divObj(i).getAttribute("class")="c_t5" Then
text=divObj(i).innerText
errormsg = text
End If
Next
End Function
QTP登录案例
猜你喜欢
转载自tengzejun508.iteye.com/blog/1945198
今日推荐
周排行