Mar 16, 2010

Descriptive Programming

Descriptive Programming

Enter or Provide Objects information (properties and their values) directly into statements is called Descriptive Programming.

In this method of script creation, we no need to have Object Repositories.

Advantages:

a) Descriptive Programming based Test scripts are faster in execution than Repository based Test scripts.

b) Scripts are portable (we can run these scripts from any machine easily)

c) Maintenance is easy (less amount of resources)

d) We can start Test Execution process even though Application is not ready.

Descriptive programming is basically 2 types.

1. Static Programming
2. Dynamic Programming

Static Programming

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

Example:
1) Invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
2) dialog("text:=Login").Activate
3) dialog("text:=Login").Winedit("attached text:=Agent Name:").Set "gcreddy"
4) dialog("text:=Login").Winedit("attached text:=Password:").Set "mercury"
5) dialog("text:=Login").Winbutton("text:=OK","width:=60").Click


Note:
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

Note2:
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.

Example 2:
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","","C:\Program Files\Internet Explorer","open"
Browser("title:=Google").Page("title:=Google").Sync
Browser("title:=Google").Navigate "http://www.icicibank.com/"



-------------------------------------------------------------------
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.


Web Examples:

Gmail Login Operation: (www.gmail.com)
----------------------------
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "www.gmail.com"
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set "gcrindia@gmail.com"
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Passwd").Set "Kurugonda7"
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("value:=Sign in").Click

---------------------------
'Code optimization
--------------------
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "www.gmail.com"
Set myPage=Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google")
myPage.WebEdit("name:=Email").Set "gcrindia@gmail.com"
myPage.WebEdit("name:=Passwd").Set "abcd1234"
myPage.WebButton("value:=Sign in").Click

Shopping Portal Registration Operation: (http://www.dealsdirect.com.au/)

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "http://www.dealsdirect.com.au/"
Browser("title:=.*").Page("url:=http://www.dealsdirect.com.au").Link("text:=Register").Click
Browser("title:=.*").Page("title:=DealsDirect.com.au Secure Login Page").WebEdit("name:=cEmail2").Set "bhavani123@gmail.com"
Browser("title:=.*").Page("title:=DealsDirect.com.au Secure Login Page").WebEdit("name:=cEmail3").Set "bhavani123@gmail.com"
Browser("title:=.*").Page("title:=DealsDirect.com.au Secure Login Page").WebEdit("name:=cPass2").Set "abcd123"
Browser("title:=.*").Page("title:=DealsDirect.com.au Secure Login Page").Image("name:=Image","file name:=image-register-and-continue-button.jpg").Click

-------------------------------------------------------------------

Dynamic Programming

Creating Description Objects, Generating Statements using Description Objects is called Dynamic descriptive Programming

-------------------------------------------

Step1: Create Description Object

Syntax:

Set Variable = Description.Create

Example:

Set Login = Description.Create

----------------------------------

Step2: Enter Properties information into Description Object

Syntax:

Description Object("Property name").Value = "Property value"

Example

Login("text").Value = "Login"

Login("width").Value = 320

----------------------------------------------------------------
Step3: Generating Statements using Description Objects

Syntax:

Test Object(Description Object).Method / Operation

Example:

Dialog(Login).Activate
---------------------------------------------------------------------------------
In this style of script generation, first we create description objects, provide properties information and use description objects in the test script.

Creating Properties Collection Objects

Set oLogin=description.Create
Set oAgent=description.Create
Set oPassword=description.Create
Set oOk=description.Create

Entering Properties Information into Objects

oLogin("text").value="Login"
oLogin("width").value=320
oLogin("height").value=204
oAgent("attached text").value="Agent Name:"
oPassword("attached text").value="Password:"
oOk("text").value="OK"

Generating Tests using Properties collection Objects

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

Dialog(oLogin).Activate
Dialog(oLogin).Winedit(oAgent).Set "gcreddy"
Dialog(oLogin).Winedit(oPassword).Set "mercury"
Dialog(oLogin).Winbutton(oOK).Click

Note1: Create Description objects and put into one library file, by associating that library file, we can generate tests.

Note2: Dynamic programming is some difficult in preparation than static programming but maintenance is very easy.

------------------------------------------------------
Examples:

Handling similar/Duplicate Objects using Index Property

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE"

Browser("name:=Google").Page("title:=Google").Sync

Browser("name:=Google").Navigate http://www.jjperfumes.com/

Browser("name:=JJ Perfumes-Discount perfume cheap brand name perfumes, fragrance & cologne online").page("title:=JJ Perfumes-Discount perfume cheap brand name perfumes, fragrance & cologne online").Link("innertext:=Register","index:=0").Click

Handling similar/Duplicate Objects using Index Property (Yahoo home page example)

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "www.yahoo.com"
Browser("CreationTime:=0").Page("title:=Yahoo! India").Link("text:=News","index:=1").Click
Note: In Yahoo Home Page 4 News Links are there, Using above script you can click on second News Link
----------------------------------------------------------------------------------
Object Repository based Test Design Vs Descriptive Programming

In Case of external Script view, difference is Only in Test Object statements, remaining all types of statements are common.

Internal Process:

In Case of Object Repository based Test, Instructions available in Test Pane Objects information available in Object Repository


In Case of Descriptive Programming, Instructions and Objects info both available in Test Pane only
------------------------------------------

Difference between Object Repository based Test and Descriptive Programming based Test in case of Test Objects Statements

a) Syntax for Single Test Object Statement (Object Repository)

TestObject("Objectname").Method or Operation

Ex:

Dialog("Login").Activate

Browser("Google").Close

----------------------------------------

a) Syntax for Single Test Object Statement (Descriptive Programming):
TestObject("propertyname:=value").Method or Operation

    Or

TestObject("property1name:=value","property2name:=value" ).Method or Operation

Ex:

Dialog("text:=Login", "width:=320").Activate

Browser("title:=Google").Close
---------------------------------------------

b) Syntax for two Test Object Statement (Object Repository):

TestObject("Objectname").ChildTestObject("Objectname").Method or Operation

Ex:

Dialog("Login").WinButton(OK").Click

Dialog("Login").WinEdit("Agent Name:").Set "abcd"

Browser("Google").Page("Google").Sync

----------------------------------------

b) Syntax for two Test Object Statement (Descriptive Programming):


TestObject("propertyname:=value").ChildTestObject("propertyname:=value").Method or Operation

Ex:

Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "abcd"

Browser("title:=Google").Page("name:=Google").Close
-----------------------------------------------------------

Note: Same process for Three Test Object Statements also 

0 comments:

Post a Comment