Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views

Aom (Automation Object Model Reference)

The document provides examples of different VBScript concepts like arrays, loops, functions, operators, and file handling. It demonstrates static and dynamic arrays, different types of loops (For, While, Do), logical and comparison operators, and how to work with files and drives using the FileSystemObject. Descriptive programming is also illustrated through static and dynamic description methods.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Aom (Automation Object Model Reference)

The document provides examples of different VBScript concepts like arrays, loops, functions, operators, and file handling. It demonstrates static and dynamic arrays, different types of loops (For, While, Do), logical and comparison operators, and how to work with files and drives using the FileSystemObject. Descriptive programming is also illustrated through static and dynamic description methods.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

AOM(AUTOMATION OBJECT MODEL REFERENCE) :

Dim qtApp 'As QuickTest.Application


Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.ActivateView "ExpertView" ' Display the Expert View
qtApp.ShowPaneScreen "ActiveScreen", True ' Display the Active Screen pane
qtApp.ShowPaneScreen "DataTable", False ' Hide the Data Table pane
qtApp.ShowPaneScreen "DebugViewer", True ' Display the Debug Viewer pane
qtApp.WindowState = "Maximized" ' Maximize the QuickTest window
qtApp.Visible = True
wait(10)
Set qtApp = Nothing

ARRAYS:
1.STATIC 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("scripting.FileSystemObject")
Dim b
set b=a.getdrive("c:\")
Dim c
c=b.availablespace
msgbox(c)
c=b.freespace
msgbox(c)
c=b.driveletter
msgbox(c)
c=b.drivetype
msgbox(c)
c=b.serialnumber
msgbox(c)
c=b.filesystem
msgbox(c)
c=b.isready
msgbox(c)
c=b.sharename
msgbox(c)
c=b.volumename
msgbox(c)
c=b.rootfolder
msgbox(c)
c=b.path
msgbox(c)

WITH STATEMENT:

1. ENTERING MANUALLY

SystemUtil.Run "E:\Program Files\Mercury Interactive\QuickTest


Professional\samples\flight\app\flight4a.exe","","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:
1.Goto Edit->Advanced->Remove “with” statement
2.Click ok present in the window that pops up

TO IMPORT DATA FROM THE DATABASE TO DATATABLE:


Steps:
1.In the data table select a cell->right click->sheet->Import->from database

TO IMPORT DATA FROM THE EXCEL TO DATATABLE:


Steps:
1.In 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("scripting.filesystemobject")
Set b=a.createtextfile("d:\malini.txt")
b.write "welcome to stc"
b.writeline "hai"
b.write "hello"
b.writeblanklines(2)
b.writeline "hello world"
b.close

'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

datatable.Import("D:\excel for login.xls")


Dim rowcount
rowcount=datatable.GetRowCount
'msgbox(rowcount)
Dim a
a=1
Dim x,y
For i=a to rowcount
datatable.SetCurrentRow(i)
set x=datatable.GetSheet(1).getparameter("Agent_Name")
set y=datatable.GetSheet(1).getparameter("Password")
x1=datatable.RawValue("Agent_Name",1)
y1=datatable.RawValue("Password",1)
SystemUtil.Run "E:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\flight4a.exe","","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
datatable.DeleteSheet(1)
DESCRIPTIVE PROGRAMMING:

STATIC METHOD:

SystemUtil.Run "E:\Program Files\Mercury Interactive\QuickTest


Professional\samples\flight\app\flight4a.exe","","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=description.Create
a("text").value="Login"
'agent name
Dim b
Set b=description.Create
b("attached text").value="Agent Name:"
'password
Dim c
Set c=description.Create
c("attached text").value="Password:"
'ok
Dim d
Set d=description.Create
d("text").value="OK"
'flight reservation
Dim e
Set e=description.Create
e("text").value="Flight Reservation"

SystemUtil.Run "E:\Program Files\Mercury Interactive\QuickTest


Professional\samples\flight\app\flight4a.exe","","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

You might also like