11-19-2013, 10:41 PM
(This post was last modified: 11-20-2013, 06:25 PM by chinmaya chirasundara nayak.)
Hi all, I am new to this forum. I executed the following two codes in QTP 10.0. The objective of both the codes are same, and that is to verify the username displayed in acti-time application. Both the codes are syntactically correct and without any run time error. But I am getting different statuses on result screen after executing the codes. Here are the two codes
Code 1 :
Result: Passed
Code 2:
Result: Failed
In both the codes, I have used "admin" as value for variable "username" and variable "s" will hold the value "User: Administrator System (admin) ". I was expecting code 2 to display passed in result screen as when "s" is splitted, all the elements in the string will be stored in the array "arr". Now while comparing each element of the array "arr" with the value of variable "username", the element arr(3) will match with the value of the variable "username" and the reporter.reportevent statement for micpass should be executed and in result screen the status would have been "Passed". But it is not happening in code 2 and the statement for micfail in the else part is executing. But Code 1 is performing well as per my expectation.
Why my code 2 is failing ? Can someone please help me out ?
Code 1 :
Code:
Dim username
username=inputbox("enter the username")
systemutil.Run "http://127.0.0.1/login.do"
with Browser("title:=acti.*").page("title:=acti.*")
.webedit("name:=username").set "admin"
.webedit("name:=pwd").set "manager"
.webbutton("name:=Login now").click
end with
s=browser("title:=acti.*").page("title:=acti.*").webelement("innertext:=User.*","html tag:=SPAN").GetROProperty("innertext")
arr=split(s)
For i=0 to ubound(arr)
If arr(i)="("&username&")" Then
desc=1
Exit for
else
desc=desc
End If
Next
If desc=1 Then
reporter.ReportEvent micPass, "un verify", "proper username is displayed"
else
reporter.ReportEvent micFail, "un verify", "improper username is displayed"
End If
browser("title:=acti.*").Close
Result: Passed
Code 2:
Code:
Dim username
username=inputbox("enter the username")
systemutil.Run "http://127.0.0.1/login.do"
with Browser("title:=acti.*").page("title:=acti.*")
.webedit("name:=username").set "admin"
.webedit("name:=pwd").set "manager"
.webbutton("name:=Login now").click
end with
s=browser("title:=acti.*").page("title:=acti.*").webelement("innertext:=User.*","html tag:=SPAN").GetROProperty("innertext")
arr=split(s)
For i=0 to ubound(arr)
If arr(i)="("&username&")" Then
reporter.ReportEvent micPass, "un verify", "proper username is displayed
Exit for
else
reporter.ReportEvent micFail, "un verify", "improper username is displayed"
End If
Next
browser("title:=acti.*").Close
Result: Failed
In both the codes, I have used "admin" as value for variable "username" and variable "s" will hold the value "User: Administrator System (admin) ". I was expecting code 2 to display passed in result screen as when "s" is splitted, all the elements in the string will be stored in the array "arr". Now while comparing each element of the array "arr" with the value of variable "username", the element arr(3) will match with the value of the variable "username" and the reporter.reportevent statement for micpass should be executed and in result screen the status would have been "Passed". But it is not happening in code 2 and the statement for micfail in the else part is executing. But Code 1 is performing well as per my expectation.
Why my code 2 is failing ? Can someone please help me out ?