SlideShare a Scribd company logo
1 of 4
QTP - VBSscript to start server
'This VBSscript to start server 'To start servers on Windows/Unix/Linux server
Dim w3sock Set w3sock = CreateObject("socket.tcp")
With w3sock
.timeout = 6000
.DoTelnetEmulation = True
.TelnetEmulation = "TTY"
.Host = "localhost:2023"
.Open
.WaitFor "login:"
WScript.Echo .Buffer
.SendLine "Provide your User ID"
.WaitFor "password:"
.SendLine "Provide your Password"
.WaitFor ">"
.SendLine "net start ""Server Mgr"""
.WaitFor ">"
WScript.Echo .Buffer
.Close
End With
Set w3sock = Nothing
‘*****************************************************************************
**********
Dictionary Object in QTP
Dictionary Object
Dictionary Object stores data key, item pairs. A Dictionary object stores the items in the array.
Each item is associated with a unique key. The key is used to retrieve an individual item and is
usually an integer or a string, but can be anything except an array.
Adavntages of using it in QTP:
1. can be used as Global variable declaration. so that any test can access the values from it in
the run time.
2. You can store and retrive any number of run time values in to dictonary.
3. It is one of the Parameterization technique we can use in QTP
Disadvantages:
we can not specify the values in the design time like Datatable , Action parameters,
environment variable.
So it is useful only in Run time , not design time
Methods:
Add Method
Adds a key and item pair to a Dictionary
object. object.Add (key, item)
Arguments
object Required. Always the name of a Dictionary object.
key Required. The key associated with the item being added.item Required.
The item associated with the key being added.
Remarks
An error occurs if the key already exists.
The following example illustrates the use of the Add method.
Dim d ‘ Create a variable.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
Items Method
Returns an array containing all the items in a Dictionary object.
object.Items( )
Remarks The object is always the name of a Dictionary object.The following code illustrates use
of the Items method:
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
a = d.Items ‘ Get the items.
For i = 0 To d.Count -1 ‘ Iterate the array.
s = s & a(i) & “
” ‘ Create return string.
Next
Msgbox s
Exists Method
Returns true if a specified key exists in the Dictionary object, false if it does not.
object.Exists(key)
Arguments
object Required. Always the name of a Dictionary object.
key Required. Key value being searched for in the Dictionary object.
Remarks
The following example illustrates the use of the Exists method.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
If d.Exists(”c”) Then
Msgbox “Specified key exists.”
Else
Msgbox “Specified key doesn’t exist.”
End If
Keys Method
Returns an array containing all existing keys in a Dictionary object.
object.Keys( )
Remarks
The object is always the name of a Dictionary object.
The following code illustrates use of the Keys method:
Dim a, d, i ‘ Create some variables.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
a = d.Keys ‘ Get the keys.
For i = 0 To d.Count -1 ‘ Iterate the array.
s = s & a(i) & “
” ‘ Return results.
Next
Msgbox s
Remove Method
Removes a key, item pair from a Dictionary object.
object.Remove(key)
Arguments
object Required. Always the name of a Dictionary object.
key Required. Key associated with the key, item pair you want to remove from the Dictionary
object.
Remarks
An error occurs if the specified key, item pair does not exist.
The following code illustrates use of the Remove method:
Dim a, d ‘ Create some variables.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
d.Add “c”, “Cairo” …
d.Remove(”b”) ‘ Remove second pair.
RemoveAll Method
The RemoveAll method removes all key, item pairs from a Dictionary object.
object.RemoveAll( )
Dim a, d, i ‘ Create some variables.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
d.Add “c”, “Cairo” …
a = d.RemoveAll ‘ Clear the dictionary.
Example :
'Defining The Dictionary ObjectDim dict Set dict = CreateObject("Scripting.Dictionary")
'Add Methoddict.Add "Company", "Indian Railway" ' Adding keys and corresponding
items.dict.Add "Tool", "QuickTest Pro"dict.Add "Website", "QTPDictionary"dict.Add "Country",
"India" x= dict.CountmsgBox "Total Number of Object in dictionary:: " & x
'Exist MethodIf dict.Exists("Country") Thenmsg = "This is India."msgBox msgElsemsg = "India is
not in a country list."End If
'Item Methodi = dict.Itemsk = dict.KeysFor x = 0 To dict.Count-1 'Iterate the array.msgbox i(x) &
" :" & k(x)Next
'Remove dict.Remove("Website")
'Remove All
dict.RemoveAll

More Related Content

Viewers also liked

An introduction to the board portal
An introduction to the board portalAn introduction to the board portal
An introduction to the board portalBhutan Canada
 
Bhutan Festival with David Suzuki
Bhutan Festival with David Suzuki Bhutan Festival with David Suzuki
Bhutan Festival with David Suzuki Bhutan Canada
 
Canaccord Genuity Advantage
Canaccord Genuity AdvantageCanaccord Genuity Advantage
Canaccord Genuity Advantagejf_richard
 
Teach in bhutan 2012
Teach in bhutan 2012Teach in bhutan 2012
Teach in bhutan 2012Bhutan Canada
 
新平台式思考 鐵則10-12(Final)
新平台式思考 鐵則10-12(Final)新平台式思考 鐵則10-12(Final)
新平台式思考 鐵則10-12(Final)Alex Chou
 
Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)
Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)
Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)Bhutan Canada
 
10 Tips for WeChat
10 Tips for WeChat10 Tips for WeChat
10 Tips for WeChatChris Baker
 
20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage ContentBarry Feldman
 

Viewers also liked (13)

Teach in Bhutan
Teach in Bhutan Teach in Bhutan
Teach in Bhutan
 
A sida web
A sida webA sida web
A sida web
 
A sida web
A sida webA sida web
A sida web
 
An introduction to the board portal
An introduction to the board portalAn introduction to the board portal
An introduction to the board portal
 
Bhutan Festival with David Suzuki
Bhutan Festival with David Suzuki Bhutan Festival with David Suzuki
Bhutan Festival with David Suzuki
 
Canaccord Genuity Advantage
Canaccord Genuity AdvantageCanaccord Genuity Advantage
Canaccord Genuity Advantage
 
Teach in bhutan 2012
Teach in bhutan 2012Teach in bhutan 2012
Teach in bhutan 2012
 
新平台式思考 鐵則10-12(Final)
新平台式思考 鐵則10-12(Final)新平台式思考 鐵則10-12(Final)
新平台式思考 鐵則10-12(Final)
 
Sang tac nhac
Sang tac nhacSang tac nhac
Sang tac nhac
 
Value line publishing, october 2012
Value line publishing, october 2012Value line publishing, october 2012
Value line publishing, october 2012
 
Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)
Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)
Tashi Delek mar-april 2014, Homestay in Haa (Matt Stretton)
 
10 Tips for WeChat
10 Tips for WeChat10 Tips for WeChat
10 Tips for WeChat
 
20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content20 Ideas for your Website Homepage Content
20 Ideas for your Website Homepage Content
 

Dictionary Object In Qtp

  • 1. QTP - VBSscript to start server 'This VBSscript to start server 'To start servers on Windows/Unix/Linux server Dim w3sock Set w3sock = CreateObject("socket.tcp") With w3sock .timeout = 6000 .DoTelnetEmulation = True .TelnetEmulation = "TTY" .Host = "localhost:2023" .Open .WaitFor "login:" WScript.Echo .Buffer .SendLine "Provide your User ID" .WaitFor "password:" .SendLine "Provide your Password" .WaitFor ">" .SendLine "net start ""Server Mgr""" .WaitFor ">" WScript.Echo .Buffer .Close End With Set w3sock = Nothing ‘***************************************************************************** ********** Dictionary Object in QTP Dictionary Object Dictionary Object stores data key, item pairs. A Dictionary object stores the items in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array. Adavntages of using it in QTP: 1. can be used as Global variable declaration. so that any test can access the values from it in the run time. 2. You can store and retrive any number of run time values in to dictonary. 3. It is one of the Parameterization technique we can use in QTP Disadvantages: we can not specify the values in the design time like Datatable , Action parameters, environment variable. So it is useful only in Run time , not design time Methods: Add Method Adds a key and item pair to a Dictionary
  • 2. object. object.Add (key, item) Arguments object Required. Always the name of a Dictionary object. key Required. The key associated with the item being added.item Required. The item associated with the key being added. Remarks An error occurs if the key already exists. The following example illustrates the use of the Add method. Dim d ‘ Create a variable. Set d = CreateObject(”Scripting.Dictionary”) d.Add “a”, “Athens” ‘ Add some keys and items. d.Add “b”, “Belgrade” Items Method Returns an array containing all the items in a Dictionary object. object.Items( ) Remarks The object is always the name of a Dictionary object.The following code illustrates use of the Items method: Set d = CreateObject(”Scripting.Dictionary”) d.Add “a”, “Athens” ‘ Add some keys and items. d.Add “b”, “Belgrade” a = d.Items ‘ Get the items. For i = 0 To d.Count -1 ‘ Iterate the array. s = s & a(i) & “ ” ‘ Create return string. Next Msgbox s Exists Method Returns true if a specified key exists in the Dictionary object, false if it does not. object.Exists(key) Arguments object Required. Always the name of a Dictionary object. key Required. Key value being searched for in the Dictionary object. Remarks The following example illustrates the use of the Exists method. Set d = CreateObject(”Scripting.Dictionary”) d.Add “a”, “Athens” ‘ Add some keys and items. d.Add “b”, “Belgrade” If d.Exists(”c”) Then Msgbox “Specified key exists.” Else Msgbox “Specified key doesn’t exist.” End If Keys Method
  • 3. Returns an array containing all existing keys in a Dictionary object. object.Keys( ) Remarks The object is always the name of a Dictionary object. The following code illustrates use of the Keys method: Dim a, d, i ‘ Create some variables. Set d = CreateObject(”Scripting.Dictionary”) d.Add “a”, “Athens” ‘ Add some keys and items. d.Add “b”, “Belgrade” a = d.Keys ‘ Get the keys. For i = 0 To d.Count -1 ‘ Iterate the array. s = s & a(i) & “ ” ‘ Return results. Next Msgbox s Remove Method Removes a key, item pair from a Dictionary object. object.Remove(key) Arguments object Required. Always the name of a Dictionary object. key Required. Key associated with the key, item pair you want to remove from the Dictionary object. Remarks An error occurs if the specified key, item pair does not exist. The following code illustrates use of the Remove method: Dim a, d ‘ Create some variables. Set d = CreateObject(”Scripting.Dictionary”) d.Add “a”, “Athens” ‘ Add some keys and items. d.Add “b”, “Belgrade” d.Add “c”, “Cairo” … d.Remove(”b”) ‘ Remove second pair. RemoveAll Method The RemoveAll method removes all key, item pairs from a Dictionary object. object.RemoveAll( ) Dim a, d, i ‘ Create some variables. Set d = CreateObject(”Scripting.Dictionary”) d.Add “a”, “Athens” ‘ Add some keys and items. d.Add “b”, “Belgrade” d.Add “c”, “Cairo” … a = d.RemoveAll ‘ Clear the dictionary. Example : 'Defining The Dictionary ObjectDim dict Set dict = CreateObject("Scripting.Dictionary") 'Add Methoddict.Add "Company", "Indian Railway" ' Adding keys and corresponding
  • 4. items.dict.Add "Tool", "QuickTest Pro"dict.Add "Website", "QTPDictionary"dict.Add "Country", "India" x= dict.CountmsgBox "Total Number of Object in dictionary:: " & x 'Exist MethodIf dict.Exists("Country") Thenmsg = "This is India."msgBox msgElsemsg = "India is not in a country list."End If 'Item Methodi = dict.Itemsk = dict.KeysFor x = 0 To dict.Count-1 'Iterate the array.msgbox i(x) & " :" & k(x)Next 'Remove dict.Remove("Website") 'Remove All dict.RemoveAll