How to Checked all check box in your application using QTP Description Language?
For Each method:-
Dim obj_chkbox
Set obj_chkbox=Discription.Create()
Obj_chkbox(“html tag”).value = “inputbox”
Obj_chkbox(“name”).value=”txt”
Dim all_chkbox,single_chkbox
Set all_chkbox=Browser (“Browser”).page (“page”).childobject(obj_chkbox)
For each single_chkbox in all_chkbox
Single_chkbox.set “ON”
Next
How to Find String in a page?
QTP has a method "GetVisibleText" to get the text from the specified area.
ex: abc = Browser("bname").Page("pname").GetVisibleText
now check the "abc" value with the string which you are searching using the INSTR....
for example,
SearchString = "Search"
abc = Browser("bname").Page("pname").GetVisibleText
If Instr(abc,SearchString) then
Msgbox " String Found"
else
Msgbox "String not Found"
End if
How to find the length of string?
Dim a
a= "welcome"
Dim b
b= len(a)
msgbox b
How to Compare the Strings?
First Get the Value and store some Variable
Example:-
Value1 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Value2 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Variable have value and now we want to compare the value.
String Compare function:
Dim Value1 Value2 MyCompare
Mycompare = strcomp(Value1 Value2 1)
QTP Keyword Frame work:-
Test Flow:-
1-Framework
a. Import data
b. Main Action
c. Export Data
a. Import Data:-
‘----------------------------------------Import input data’s-----------------------------------------------
Datatable.AddSheet “dlogin”
Datatable.AddSheet “dinvitelist”
Datatable.AddSheet “dmessage”
Datatable.ImportSheet “C:\A.xls”,”login”,”dlogin”
Datatable.ImportSheet “C:\A.xls”,”invitelist”,”dinvitelist”
Datatable.ImpoertSheet “C:\A.xls”,”message”,”dmessage”
‘---------------------------------------- Import Testcase and Teststeps---------------------------------
Datatable.AddSheet “dtestcase”
Datatable.AddSheet “dteststeps”
Datatable.importsheet “C:\B.xls”,”TestCases”,”dtestcase”
Datatable.ImportSheet “C:\B.xls”,”TestSteps”,”dteststep”
b. Main Action:-
‘------------------------------------------ Declare Variable -----------------------------------------------
‘Declare the Variable being used within our scripts
Option Explicit
Dim n_email, n_pswd, n_n_invite_elist, n_invite_message
Dim n_url
Dim dil_rows,dcrows,tsrows
Dim I,j,k
Dim ts_result,tc_result ‘ Added by karthik on 23rd des 2010
‘----------------------------------------------- Main Code ------------------------------------------------
‘Parameterize the Test
n_url = “http:\www.ning.com
‘Test parameterization login default
n_email=Datatable.value (“Email”,”dlogin”)
n_pswd=Datatable.Value (“Pswd”,dlogin”)
‘Default Test Case and Test Steps Result
tc_result = “Pass”
ts_result = “Pass”
‘Get dinvitelist rowcount
dil_rows=Datatable.GetSheet(“dinvitelist”).GetRowCount
n_invite_elist
‘Get the invite list and messages
For k =1 to dil_rows
Datatable.Getsheet(“dinvitelist”).SetCurrentRow(k)
n_invite_elist=n_invite_elist & Datatable.Value (“Email”,”dinvitelist”)
if k<>dil_rows Then
n_invite_elist = n_invite_elist & “”
End If
Next
n_invite_message = datatable.value (“Message”,”dmessage”)
‘Main Framework Code
tcrows=Datatable.Getsheet (“dtestcases”).Getrowcount
tsrows=Datatable.Getsheet (“dteststeps”).Getrowcount
For i=0 to tcrows
Datatable.GetSheet (“dtestcases”).SetCurrentRow(i)
If Datatable.Value(“Execute”,”dtestcases”)= “Y” Then
For j=1 to tsrows
Datatable.GetSheet (“dteststeps”).SetCurrentRow(j)
If Datatable.Value (“TCID”,”dtestcases”)=Datatable.Value(“TCID”,”dteststeps”) Then
Select Case Datatable.Value(“Keyword”,”dteststeps”)
Case “browserhomepage”
ts_result = browsehomepage(n_url)
Case “login”
ts_result=login(n_email,n_pswd)
Case “invitefriend”
ts_result = invitefriend()
Case “invitedata”
ts_result = invitedata(n_invite_elist,n_invite_message)
Case “invitecheck”
ts_result=invitecheck()
Case “logout”
ts_result = logout()
Case “Closebrowser”
ts _result= closebrowser()
Case “mypage”
ts_result=mypage()
End Select
Datatable.Value(“Result”,”dteststeps”)= ts_result
if tc_result=”PASS” Then
tc_result=ts_result
End If
End if
Next
Datatable.Value (“Result”,”dtestcases”)= tc_result
End If
Next
c. Export Data:-
----------------------------------- Export Output of Test Case and Test Steps-----------------------------
Datatable.ExportSheet (“C:\D.xls”,”dtestcases”)
Datatable.ExportSheet (“C:\D.xls”,”dteststeps”)
2.Ning Functional Frameworks
‘--------------------------------------Start of Function-----------------------------------------------------‘Browse to ning.com
Function browsehomepage(n_url)
SystemUtil.Run “ieexplore.exe”,”n_url”
Browsehomepage=”Pass”
End Function
‘Function to Login to ning.com
Function Login(n_Email,n_pswd)
Logout()
If Browser(“ninghome”).page(“home”).link(“Signin”).Exist(4) Then
Browser(“ninghome”).Page(“home”).link(“Signin”).click
Browser(“signin”).page(“signin”).webedit(“Email”).Set n_email
Browser(“Signin”).page(“signin).webedit(“Pswd”).Set n_pswd
Browser(Signin).Page(“Signin”).webbutton(“signin”).click
End If
If Browser(“signin”).Dialog(“alert”).Webbutton(“Yes”).Exist Then
Browser(“Signin”).Dialog(“alert”).Webbutton(“yes”).click
End If
Login=”Pass”
End Function
Function Logout()
Set ning_Signout=Browser(“ClassName:=.*”).link(“text=signout”)
If ning_signout.Exist(4) then
Ning_signout.click
End if
Logut=”Pass”
End Function
Function invitefriends()
Dim fun_result()
‘Start of Error handling
On Error Resume Next
‘Instruct QTP to skip anymore and move to next line
Browser(“newuser”).page(“Newuser”).link(“invitfriend”).click
If err.number<>0 Then
Reporter.Reportevent micfail,”Failed”,”Error on somewhere in steps”
Fun_result=”Fail”
Else
Reporter.reportevent micpass,”Passed”,”Step passed”
Fun_result=”Pass”
End if
On error goto 0
Invitefriend=fun_result
End Function
Function invitedata(n_invite_elist, n_invite_message)
Dim my_error,fun_result
On Error Resume next
Browser(“invite”).page(“invite”).set n_invite_elist
Browser(“invite”).Page(“invite”).Set n_invite_message
Browser(“invite”).page(“invite”),Webbutton(invite).click
Myerror= “Error Desc/err.number:”& Err.Description&”/”& err.number
If error number <>0 then
Reporter.Reportevent micfail,”Failed”,”Error on somewhere in steps”
Fun_result=”Fail”
Else
Reporter.reportevent micpass,”Passed”,”Step passed”
Fun_result=”Pass”
End if
On error goto 0
Invitedata=fun_result
End Function
Function Invitecheck()
If Browser(“invite”).page(“Invite).webelement(“your invitation has been sent”).Exist Then
End if
Invitecheck=”pass”
End Function
Function Closebrowser()
If browser(“invite”).close
Closebrowser=”pass”
End function
Function mypage()
On error resume next
Browser(“verify ur email add”).page(“invite”).link(“clickemail”).click
If On error <> 0 then
Mypage=”pass”
Else
Mypage=”Fail”
End if
On error goto 0
End Function
For Each method:-
Dim obj_chkbox
Set obj_chkbox=Discription.Create()
Obj_chkbox(“html tag”).value = “inputbox”
Obj_chkbox(“name”).value=”txt”
Dim all_chkbox,single_chkbox
Set all_chkbox=Browser (“Browser”).page (“page”).childobject(obj_chkbox)
For each single_chkbox in all_chkbox
Single_chkbox.set “ON”
Next
How to Find String in a page?
QTP has a method "GetVisibleText" to get the text from the specified area.
ex: abc = Browser("bname").Page("pname").GetVisibleText
now check the "abc" value with the string which you are searching using the INSTR....
for example,
SearchString = "Search"
abc = Browser("bname").Page("pname").GetVisibleText
If Instr(abc,SearchString) then
Msgbox " String Found"
else
Msgbox "String not Found"
End if
How to find the length of string?
Dim a
a= "welcome"
Dim b
b= len(a)
msgbox b
How to Compare the Strings?
First Get the Value and store some Variable
Example:-
Value1 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Value2 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Variable have value and now we want to compare the value.
String Compare function:
Dim Value1 Value2 MyCompare
Mycompare = strcomp(Value1 Value2 1)
QTP Keyword Frame work:-
Test Flow:-
1-Framework
a. Import data
b. Main Action
c. Export Data
a. Import Data:-
‘----------------------------------------Import input data’s-----------------------------------------------
Datatable.AddSheet “dlogin”
Datatable.AddSheet “dinvitelist”
Datatable.AddSheet “dmessage”
Datatable.ImportSheet “C:\A.xls”,”login”,”dlogin”
Datatable.ImportSheet “C:\A.xls”,”invitelist”,”dinvitelist”
Datatable.ImpoertSheet “C:\A.xls”,”message”,”dmessage”
‘---------------------------------------- Import Testcase and Teststeps---------------------------------
Datatable.AddSheet “dtestcase”
Datatable.AddSheet “dteststeps”
Datatable.importsheet “C:\B.xls”,”TestCases”,”dtestcase”
Datatable.ImportSheet “C:\B.xls”,”TestSteps”,”dteststep”
b. Main Action:-
‘------------------------------------------ Declare Variable -----------------------------------------------
‘Declare the Variable being used within our scripts
Option Explicit
Dim n_email, n_pswd, n_n_invite_elist, n_invite_message
Dim n_url
Dim dil_rows,dcrows,tsrows
Dim I,j,k
Dim ts_result,tc_result ‘ Added by karthik on 23rd des 2010
‘----------------------------------------------- Main Code ------------------------------------------------
‘Parameterize the Test
n_url = “http:\www.ning.com
‘Test parameterization login default
n_email=Datatable.value (“Email”,”dlogin”)
n_pswd=Datatable.Value (“Pswd”,dlogin”)
‘Default Test Case and Test Steps Result
tc_result = “Pass”
ts_result = “Pass”
‘Get dinvitelist rowcount
dil_rows=Datatable.GetSheet(“dinvitelist”).GetRowCount
n_invite_elist
‘Get the invite list and messages
For k =1 to dil_rows
Datatable.Getsheet(“dinvitelist”).SetCurrentRow(k)
n_invite_elist=n_invite_elist & Datatable.Value (“Email”,”dinvitelist”)
if k<>dil_rows Then
n_invite_elist = n_invite_elist & “”
End If
Next
n_invite_message = datatable.value (“Message”,”dmessage”)
‘Main Framework Code
tcrows=Datatable.Getsheet (“dtestcases”).Getrowcount
tsrows=Datatable.Getsheet (“dteststeps”).Getrowcount
For i=0 to tcrows
Datatable.GetSheet (“dtestcases”).SetCurrentRow(i)
If Datatable.Value(“Execute”,”dtestcases”)= “Y” Then
For j=1 to tsrows
Datatable.GetSheet (“dteststeps”).SetCurrentRow(j)
If Datatable.Value (“TCID”,”dtestcases”)=Datatable.Value(“TCID”,”dteststeps”) Then
Select Case Datatable.Value(“Keyword”,”dteststeps”)
Case “browserhomepage”
ts_result = browsehomepage(n_url)
Case “login”
ts_result=login(n_email,n_pswd)
Case “invitefriend”
ts_result = invitefriend()
Case “invitedata”
ts_result = invitedata(n_invite_elist,n_invite_message)
Case “invitecheck”
ts_result=invitecheck()
Case “logout”
ts_result = logout()
Case “Closebrowser”
ts _result= closebrowser()
Case “mypage”
ts_result=mypage()
End Select
Datatable.Value(“Result”,”dteststeps”)= ts_result
if tc_result=”PASS” Then
tc_result=ts_result
End If
End if
Next
Datatable.Value (“Result”,”dtestcases”)= tc_result
End If
Next
c. Export Data:-
----------------------------------- Export Output of Test Case and Test Steps-----------------------------
Datatable.ExportSheet (“C:\D.xls”,”dtestcases”)
Datatable.ExportSheet (“C:\D.xls”,”dteststeps”)
2.Ning Functional Frameworks
‘--------------------------------------Start of Function-----------------------------------------------------‘Browse to ning.com
Function browsehomepage(n_url)
SystemUtil.Run “ieexplore.exe”,”n_url”
Browsehomepage=”Pass”
End Function
‘Function to Login to ning.com
Function Login(n_Email,n_pswd)
Logout()
If Browser(“ninghome”).page(“home”).link(“Signin”).Exist(4) Then
Browser(“ninghome”).Page(“home”).link(“Signin”).click
Browser(“signin”).page(“signin”).webedit(“Email”).Set n_email
Browser(“Signin”).page(“signin).webedit(“Pswd”).Set n_pswd
Browser(Signin).Page(“Signin”).webbutton(“signin”).click
End If
If Browser(“signin”).Dialog(“alert”).Webbutton(“Yes”).Exist Then
Browser(“Signin”).Dialog(“alert”).Webbutton(“yes”).click
End If
Login=”Pass”
End Function
Function Logout()
Set ning_Signout=Browser(“ClassName:=.*”).link(“text=signout”)
If ning_signout.Exist(4) then
Ning_signout.click
End if
Logut=”Pass”
End Function
Function invitefriends()
Dim fun_result()
‘Start of Error handling
On Error Resume Next
‘Instruct QTP to skip anymore and move to next line
Browser(“newuser”).page(“Newuser”).link(“invitfriend”).click
If err.number<>0 Then
Reporter.Reportevent micfail,”Failed”,”Error on somewhere in steps”
Fun_result=”Fail”
Else
Reporter.reportevent micpass,”Passed”,”Step passed”
Fun_result=”Pass”
End if
On error goto 0
Invitefriend=fun_result
End Function
Function invitedata(n_invite_elist, n_invite_message)
Dim my_error,fun_result
On Error Resume next
Browser(“invite”).page(“invite”).set n_invite_elist
Browser(“invite”).Page(“invite”).Set n_invite_message
Browser(“invite”).page(“invite”),Webbutton(invite).click
Myerror= “Error Desc/err.number:”& Err.Description&”/”& err.number
If error number <>0 then
Reporter.Reportevent micfail,”Failed”,”Error on somewhere in steps”
Fun_result=”Fail”
Else
Reporter.reportevent micpass,”Passed”,”Step passed”
Fun_result=”Pass”
End if
On error goto 0
Invitedata=fun_result
End Function
Function Invitecheck()
If Browser(“invite”).page(“Invite).webelement(“your invitation has been sent”).Exist Then
End if
Invitecheck=”pass”
End Function
Function Closebrowser()
If browser(“invite”).close
Closebrowser=”pass”
End function
Function mypage()
On error resume next
Browser(“verify ur email add”).page(“invite”).link(“clickemail”).click
If On error <> 0 then
Mypage=”pass”
Else
Mypage=”Fail”
End if
On error goto 0
End Function