AOM(AUTOMATION OBJECT MODEL REFERENCE) :
Dim qtApp 'As [Link]
Set qtApp = CreateObject("[Link]")
[Link]
[Link] "ExpertView" ' Display the Expert View
[Link] "ActiveScreen", True ' Display the Active Screen pane
[Link] "DataTable", False ' Hide the Data Table pane
[Link] "DebugViewer", True ' Display the Debug Viewer pane
[Link] = "Maximized" ' Maximize the QuickTest window
[Link] = True
wait(10)
Set qtApp = Nothing
ARRAYS:
[Link] ARRAY:
Dim a(2)
a(0)="malini"
a(1)="mercury"
a(2)="qtp"
For i=0 to 2
msgbox(a(i))
next
2. DYNAMIC ARRAY:
EXAMPLE 1:
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
For i=0 to 1
msgbox(a(i))
next
EXAMPLE 2:
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
ReDim a(2)’USING REDIM WITHOUT PRESERVE
a(2)="eeee"
For i=0 to 2
msgbox(a(i))
next
EXAMPLE 3:
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
ReDim preserve a(2)’REDIM WITH PRESERVE KEYWORD
a(2)="eeee"
For i=0 to 2
msgbox(a(i))
next
ERASE STATEMENT:
1. Effect of ERASE STATEMENT on STATIC ARRAY-Deletes only the values but
memory will be there
Dim a(2)
a(0)="malini"
a(1)="mercury"
a(2)="qtp"
For i=0 to 2
msgbox(a(i))
next
Erase a
For i=0 to 2
msgbox(a(i))
next
2. Effect of ERASE STATEMENT on DYNAMIC ARRAY-Deletes the memory itself
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
For i=0 to 1
msgbox(a(i))
next
Erase a
For i=0 to 1
msgbox(a(i))
next
msgbox(a(2))
WORKING WITH DRIVES:
Dim a
Set a=createobject("[Link]")
Dim b
set b=[Link]("c:\")
Dim c
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
c=[Link]
msgbox(c)
WITH STATEMENT:
1. ENTERING MANUALLY
[Link] "E:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\[Link]","","E:\Program Files\Mercury
Interactive\QuickTest Professional\samples\flight\app\","open"
With Dialog("Login")
.activate
.WinEdit("Agent Name:").set "malini"
End with
2. AUTOMATICALLY ADDING WITH STATEMENT:
STEPS:
i)goto Tools->Options->General tab->enable a checkbox called “automatically generate
the “with statement” for _2___ or more objects
ii)click apply->click ok
iii)generate the script
iv)once the script is generated then you can see with statement automatically included
Note:
To remove the added with statement follow the following statement
STEPS:
[Link] Edit->Advanced->Remove “with” statement
[Link] ok present in the window that pops up
TO IMPORT DATA FROM THE DATABASE TO DATATABLE:
Steps:
[Link] the data table select a cell->right click->sheet->Import->from database
TO IMPORT DATA FROM THE EXCEL TO DATATABLE:
Steps:
[Link] the data table select a cell->right click->sheet->Import->from Excel
EXIT STATEMENT:
‘EXIT FOR STATEMENT
Dim a
Dim b
For i=1 to 10
a=inputbox("enter the vaue for a")
b=inputbox("enter the value for b")
if(a>b) then
msgbox("a is greater")
else
Exit for
end if
Next
'EXIT DO STATEMENT
Dim a
Dim b
Dim i
Do until(i=10)
a=inputbox("enter the vaue for a")
b=inputbox("enter the value for b")
if(a>b) then
msgbox("a is greater")
else
Exit do
end if
i=i+1
loop
EXIT FUNCTION EXAMPLE
function add1(a,b)
Dim c
add1=cint(a)+cint(b)
msgbox(add1)
if(add1>10) then
msgbox("add1 is greater then 10")
else
Exit function
end if
msgbox("within the function")
End function
Dim a
Dim b
a=inputbox("enter the vaue for a")
b=inputbox("enter the value for b")
msgbox("value of add1 in main script is"&add1(a,b))
FILE HANDLING:
Dim a
Set a=createobject("[Link]")
Set b=[Link]("d:\[Link]")
[Link] "welcome to stc"
[Link] "hai"
[Link] "hello"
[Link](2)
[Link] "hello world"
[Link]
'if then else
Dim a
Dim b
Dim c
a=inputbox("enter the value for a:")
b=inputbox("enter the value for b:")
c=inputbox("enter the value for c:")
if(a>b) then
msgbox(a)
else if(b>c) then
msgbox(b)
end if
msgbox(c)
end if
LOOPING STATEMENTS:
'WHILE LOOP
Dim a
a=4
while(a<10)
msgbox(a)
a=a+1
wend
'FOR LOOP
Dim a
For a=5 to 10
msgbox(a)
Next
Dim a
a=3
'do loop until
Do
msgbox(a)
a=a+1
Loop until(a>5)
'DO UNTIL LOOP
Dim a
a=3
Do until(a>5)
msgbox(a)
a=a+1
Loop
Dim a
a=10
'DO WHILE
Do while(a>5)
msgbox(a)
a=a-1
Loop
'
‘SELECT CASE
Dim str
str="y"
Select Case str
Case "a"
msgbox("vowel")
Case "e"
msgbox("vowel")
Case "i"
msgbox("vowel")
Case "o"
msgbox("vowel")
Case "u"
msgbox("vowel")
Case else
msgbox("not a vowel")
'FUNCTION PROCEDURE
function add1(a,b)
add1=a+b'RETURNS A VALUE
End function
Dim a
Dim b
a=10
b=20
msgbox(add1(a,b))
ON ERROR RESUME NEXT STATEMENT:
Dim a
Dim b
a=10
b=0
Dim c
On error resume next 'to enable error handling
c=a/b
msgbox(c)
Note:
To disable the error handling statement the use ON ERROR GOTO 0
Dim a
Dim b
a=10
b=0
Dim c
On error resume next 'to enable error handling
on Error Goto 0 'to disable error handling
c=a/b
msgbox(c)
OPERATORS IN VBSCRIPT:
'arithmetic operators
Dim a
Dim b
a=10.560
b=45.6
Dim c
c=a+b
msgbox(c)
c=a-b
msgbox(c)
c=a*b
msgbox(c)
c=a/b
msgbox(c)
c=a\b
msgbox(c)
c=a&b
msgbox(c)
‘logical operators
NOT:
Dim a
Dim b
a=true
b=true
msgbox(not a)
AND:
Dim c
c=(a and b)
msgbox(c)
OR:
c=(a or b)
msgbox(c)
XOR:
Dim a
Dim b
a=30
b=80
if(a>b xor a=30) then
msgbox("if part is executed")
else
msgbox("else part is executed")
end if
LOGICAL OPERATORS:
> operator
Dim a
Dim b
a=50
b=10
if(a>b) then
msgbox("a is greater")
else
msgbox("b is greater")
end if
<operator
Dim a
Dim b
a=5
b=10
if(a<b) then
msgbox("a is smaller")
else
msgbox("b is smaller")
end if
'<=operator
Dim a
Dim b
a=5
b=10
if(a<=b) then
msgbox("a is <=")
else
msgbox("b is <=")
end if
'>=operator
Dim a
Dim b
a=50
b=10
if(a>=b) then
msgbox("a is >=")
else
msgbox("b is >=")
end if
'<> operator
Dim a
Dim b
a=5
b=10
if(a<>b) then
msgbox("a is <>r")
else
msgbox("b is <>")
end if
'=operator
Dim a
Dim b
a=10
b=10
if(a=b) then
msgbox("a is equal to b")
else
msgbox("b is greater")
end if
PARAMETERISATION THROUGH SCRIPTING:-Importing data FROM
EXCEL
[Link]("D:\excel for [Link]")
Dim rowcount
rowcount=[Link]
'msgbox(rowcount)
Dim a
a=1
Dim x,y
For i=a to rowcount
[Link](i)
set x=[Link](1).getparameter("Agent_Name")
set y=[Link](1).getparameter("Password")
x1=[Link]("Agent_Name",1)
y1=[Link]("Password",1)
[Link] "E:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\[Link]","","E:\Program Files\Mercury
Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set x1
Dialog("text:=Login").WinEdit("attached text:=Password:").SetSecure y1
wait(5)
Dialog("text:=Login").WinButton("text:=OK").Click
Window("text:=Flight Reservation").Close
a=a+1
Next
[Link](1)
DESCRIPTIVE PROGRAMMING:
STATIC METHOD:
[Link] "E:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\[Link]","","E:\Program Files\Mercury
Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "malini"
Dialog("text:=Login").WinEdit("attached text:= Password:").SetSecure "mercury"
Dialog("text:=Login").WinButton("text:=OK").Click
Window("text:=Flight Reservation").Close
DYNAMIC METHOD:
login
Dim a
Set a=[Link]
a("text").value="Login"
'agent name
Dim b
Set b=[Link]
b("attached text").value="Agent Name:"
'password
Dim c
Set c=[Link]
c("attached text").value="Password:"
'ok
Dim d
Set d=[Link]
d("text").value="OK"
'flight reservation
Dim e
Set e=[Link]
e("text").value="Flight Reservation"
[Link] "E:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\[Link]","","E:\Program Files\Mercury
Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog(a).Activate
Dialog(a).WinEdit(b).set "malini"
Dialog(a).WinEdit(c).setsecure "mercury"
Dialog(a).WinButton(d).click
Window(e).close