Software Testing Social Network

Free Software Testing Tutorial and Quality Assurance Portal

Sign in with Facebook
 
  • Increase font size
  • Default font size
  • Decrease font size

Introduction to QTP (QuickTest Professional) Part3

VB Script  Data Types

alt 

  • Declaring Variables
  • Naming Restrictions
  • Scope and Lifetime of Variables
  • Assigning Values to Variables
  • Scalar Variables and Array Variables
  • Creating Constants
    VB Script basics - Operators
  • alt
  • VB Script basics  Conditions & Looping
  • Conditional Statements
    If...Then...Else statement
    Select Case statement
     Looping
    Do...Loop: Loops while or until a condition is true.

    While...Wend: Loops while a condition is true.

     For...Next: Uses a counter to run statements a specified number of times.

     For each...Next: Repeats a group of statements for each item in a collection or each element of an array.
    {mosgoogle}
  • VB Script basics  Functions
    alt

Key areas in QTP 

  • About the script structure
  • Object Identification Mechanism
  • Active screen customization
  • Actions (Simple, Nested, External, Re-usable)
  • Parameterization (Different Types)
  • Checkpoints (Programmatic Methodology)
  • Descriptive programming
  • Adv. Synchronization points
  • Exception Handling
  • Microsoft Automation Object Model

About the script structure 

alt 

Sample Script  QTP Functions
 
sample 1 - Capturing the snapshot of the combo box control
Window("Flight Reservation").WinComboBox("Fly From:").CaptureBitmap "C:\mybmp.bmp",true

'sample 2 - Capturing the snapshot of the entire window
Window("Flight Reservation").CaptureBitmap "C:\mybmp.bmp"

'sample 3 - Getting all the items from the combo box
My_Cnt = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
msgbox My_Cnt

For i = 1 to My_Cnt
    ' the combo box item index will start from zero.
    My_item = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i-1)
    Msgbox My_item
Next

'sample 4 - Getting the entire content of the combo box
    Var_Content = Window("Flight Reservation").WinComboBox("Fly From:").GetContent
    Msgbox Var_Content
'sample 5 - Selecting an item from the combo - Using Index
Window("Flight Reservation").WinComboBox("Fly From:").Select(5)

'sample 6 - Selecting an item from the combo - Using Value
Window("Flight Reservation").WinComboBox("Fly From:").Select("London")

'sample 7 - Selecting an item from the combo - Using Variable
Var_Item = "Zurich"
Window("Flight Reservation").WinComboBox("Fly From:").Select(Var_Item)

'sample 8 - Getting the value of selected item
Var_Sel = Window("Flight Reservation").WinComboBox("Fly From:").GetSelection
Msgbox Var_Sel

'sample 9 - Edit box functions
Window("Flight Reservation").Activate
Call wait(8)
Window("Flight Reservation").WinEdit("Name:").Set "DasDas
Call wait(8)
Window("Flight Reservation").WinEdit("Name:").Type "tryhard
Call wait(8)
Window("Flight Reservation").WinEdit("Name:").Set "DasDas
Call wait(8)
Window("Flight Reservation").Activate
Call wait(8)
Window("Flight Reservation").ActiveX("MaskEdBox").Set "111111

' Some FUM's (Frequently Used Methods)

'GetROProperty
Var_Text = Window("Flight Reservation").WinEdit("Name:").GetROProperty("AttachedText")
Msgbox Var_Text
Var_Enab = Window("Flight Reservation").WinEdit("Name:").GetROProperty("Enabled")
Msgbox Var_Enab

'Exist
If Window("Flight Reservation").WinEdit("Name:").Exist(5) Then
    Msgbox "The Editbox exists"
Else
    Msgbox "The Editbox does not exist"
End if

'Wait
Wait(10) ' The QTP will sleep for 10 seconds

'Msgbox
Msgbox "Hello QTP"

Object Identification Mechanism 

  • Object Identification
  • About the script structure
  • Object Identification Mechanism
  • Active screen customization
  • Actions (Simple, Nested, External, Re-usable)
  • Parameterization (Different Types)
  • Checkpoints (Programmatic Methodology)
  • Descriptive programming
  • Adv. Synchronization points
  • Exception Handling
  • Microsoft Automation Object Model

Sample Script – QTP Functions

‘sample 1 - Capturing the snapshot of the combo box control

Window("Flight Reservation").WinComboBox("Fly From:").CaptureBitmap "C:\mybmp.bmp",true
'sample 2 - Capturing the snapshot of the entire window
Window("Flight Reservation").CaptureBitmap "C:\mybmp.bmp"
'sample 3 - Getting all the items from the combo box
My_Cnt = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
msgbox My_Cnt
For i = 1 to My_Cnt
' the combo box item index will start from zero.
My_item = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i-1)
Msgbox My_item
Next
'sample 4 - Getting the entire content of the combo box
Var_Content = Window("Flight Reservation").WinComboBox("Fly From:").GetContent
Msgbox Var_Content

'sample 5 - Selecting an item from the combo - Using Index

Window("Flight Reservation").WinComboBox("Fly From:").Select(5)

'sample 6 - Selecting an item from the combo - Using Value
Window("Flight Reservation").WinComboBox("Fly From:").Select("London")
'sample 7 - Selecting an item from the combo - Using Variable
Var_Item = "Zurich"
Window("Flight Reservation").WinComboBox("Fly From:").Select(Var_Item)
'sample 8 - Getting the value of selected item
Var_Sel = Window("Flight Reservation").WinComboBox("Fly From:").GetSelection
Msgbox Var_Sel

'sample 9 - Edit box functions
Window("Flight Reservation").Activate
Call wait(8)
Window("Flight Reservation").WinEdit("Name:").Set "DasDas“
Call wait(8)
Window("Flight Reservation").WinEdit("Name:").Type "tryhard“
Call wait(8)
Window("Flight Reservation").WinEdit("Name:").Set "DasDas“
Call wait(8)
Window("Flight Reservation").Activate
Call wait(8)
Window("Flight Reservation").ActiveX("MaskEdBox").Set "111111“

q' Some FUM's (Frequently Used Methods)
'GetROProperty
Var_Text = Window("Flight Reservation").WinEdit("Name:").GetROProperty("AttachedText")
Msgbox Var_Text
Var_Enab = Window("Flight Reservation").WinEdit("Name:").GetROProperty("Enabled")
Msgbox Var_Enab
'Exist
If Window("Flight Reservation").WinEdit("Name:").Exist(5) Then
Msgbox "The Editbox exists"
Else
Msgbox "The Editbox does not exist"
End if
'Wait
Wait(10) ' The QTP will sleep for 10 seconds
'Msgbox

Msgbox "Hello QTP"

NExt Introduction to QTP (QuickTest Professional) Part4

Share
 



Related Articles: