Wednesday, December 15, 2010

Static Programming

In this style of script generation, we provide objects information directly into the script.

Ex:

Invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

dialog("text:=Login").Activate

dialog("text:=Login").Winedit("attached text:=Agent Name:").Set "asdf"

dialog("text:=Login").Winedit("attached text:=Password:").Set "mercury"

dialog("text:=Login").Winbutton("text:=OK","width:=60").Click

Note 1:

  1. Dialog, WinEdit and WinButton – Test Objects
  2. text, attached text - Property names
  3. Login, Agent Name:, Password:, OK - Property values or Logical Names of the Object
  4. Activate, Set, Setsecure, Click - Methods

Note 2:

If we feel one property information is not sufficient for recognizing the object uniquely, then we can provide more properties information by separating with commas.

Note 3:

If we want to get objects information (Test objects, properties and values), we can use object spy feature. This feature is available in Tools Menu, in local repository and in repository manager.

If we want maintain ‘Objects information’ in centralized location then we can use Constants.

Steps:

Creating Constants:

Const Login="text:=Login", Agent="attached text:=Agent Name:"

Const Pwd ="attached text:=Password:", Ok="text:=OK"

Note: we can declare no of Constants in a line by separating with Camas (,), if we take other line then we have to use Const Statement again.

Creating a Library file

Place Constants in Notepad and save as .vbs file

Associate the Library file to QTP (File->Settings->Resources-> Click add (+) icon-> Browse path of the Library file->Click Apply and click Ok buttons

Otherwise, we can load the library file during run-time

Syntax:

ExecuteFile “Path of the Library file(.vbs)”

After that create the Test Script using Constants

Creating the Test Script using Constants:

Invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog(Login).Activate

Dialog(Login).Winedit(Agent).Set "asdf"

Dialog(Login).Winedit(Pwd").Set "mercury"

Dialog(Login).Winbutton(Ok).Click

Advantages:

If we maintain Object Information in the centralized location, then we can handle modifications easily.