method method is some thing which is used by

21
For QTP Realtime Scripts, visit www.ramupalanki.c om Methods Method : Method is some thing which is used by QTP to Perform any action is called a method.  Example : Click, set …. Etc 1. Capture Bit Map() : This method used for capturing a snap shot of an object during Execution and stores in a desired location. When you want to send Defect to the developer, this captured bitmap can also be sent in order to understand the error/defect easily. Syntax : Object  Hierarchy. captureBitma p “path of the location with a file name .bmp extension” Example: Window("Flight Applicaiton").Dialog("Open Order").WinButton("OK").captureBitmap (“d:\fa1.bmp”) : captured snapshot / bit map will be stored in “D” drive with file name as fa1.bmp Put the tool under recording mode Open the flight application Enter username an password Click on OK After logged in , try to open an existing order by clicking on open order. Open order window will appears Assume that you find some errors on that window and want to capture bitmap for that window Stop recording

Upload: ramu-palanki

Post on 09-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 1/21

For QTP Realtime Scripts, visit www.ramupalanki.com

Methods

Method : Method is some thing which is used by QTP to Perform any action is called a

method. Example : Click, set …. Etc

1. Capture Bit Map() : This method used for capturing a snap shot of an object during Execution an

stores  in a desired location. When you want to send Defect to the developer, thi

captured bitmap can also be sent in order to understand the error/defect easily.

Syntax : Object  Hierarchy

captureBitmap “path of th

location with a file name.bmp extension” 

Example: Window("Flight Applicaiton").Dialog("Open Order").WinButton("OK").captureBitmap (“d:\fa1.bmp

: captured snapshot / bit map will be stored in “D” drive with file name as fa1.bmp

Put the tool under recording mode

Open the flight application

Enter username an password

Click on OK

After logged in , try to open an existing order by clicking on open order.

Open order window will appears

Assume that you find some errors on that window and want to capture bitmap for that window

Stop recording

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 2/21

At the end of present script ( or next line of the error’s window script)

insert the capture method (say OH. CaptureBitmap "d:\bop.bmp" )

Run the test

After Test is executed successfully and that bitmap/ snap shot will be

stored in the location d:\bop.bmp

That you can send as attachment to the developer along with defect reporting

2. Exist () : The main purpose of this method is to check whether the object/ window is existing or NOT.

Exist method is used for checking the object’s existence. If the object is existing

then it will return TRUE and continue the execution. Otherwise , it will wait till the object exists or 

upto the maximum time. Meanwhile at any point of time the object exists it will return TRUE and

continue its execution, otherwise, after the maximum time is finished it will return FALSE and

continue its execution.

* Exist method will make the QTP to wait till the default time Plus extra time (if any)

Syntax : Object  Hierarchy. Exists [(Extra time in seconds] 

Exaple : var = window(“flight application”).Exists (10)

Msgbox var  : gives True or false

Open the flight application and put tool in recoding mode

Open the order by clicking on open order, it will displays the open order window

Enter an existing order number and click on Ok. That order will be opened.

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 3/21

For QTP Realtime Scripts, visit www.ramupalanki.com Stop recording.

Now to check whether that window is available or not

 put this code before that window’s script

var=Window("Flight Reservation").Dialog("OpenOrder").Exist(10) msgbox var : gives True or false

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 4/21

  If True it will continue execution else stops

3. WaitProperty () : This method is used for make the tool to wait based on the object property’s

value or up to maximum time .

Syntax : Object  Hierarchy. Waitproperty “propertyName”, Property value, extra time in milliseconds

Example :

Open the flight application and put tool in recoding mode

Open the order by clicking on open order, it will displays the open order window

Enter an existing order number and click on Ok. That order will be opened.

Stop recording.

Now , if you want to wait the tool even after clicking on OK button

take the property name ( as text),value( as OK) from object repository and

put extra time in milliseconds.

For example : OH.WaitProperty "text", OK,10000

And put the above code after the OK button clicked statement in the script

Run the test

Analyze the results

4. Wait () : This method is used for making the tool to wait till the maximum time is elapsed

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 5/21

For QTP Realtime Scripts, visit www.ramupalanki.com

Syntax : Object  Hierarchy. Wait (Time in seconds)

Example :

Open the flight application and put tool in recoding mode

Open the order by clicking on open order, it will displays the open order window

Enter an existing order number and click on Ok. That order will be opened.

Stop recording.

Now , if you want to wait the tool at any point of time

Put the code any where in between the

script For example : wait (10)

Run the test

Analyze the results

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 6/21

Simple and Regular used Methods

1. Click Method : Which is used for clicking on a specified object

Syntax : Object  Hierarchy. Click [ x, y [button]] 

0 for Left Click

1 for Right Click

2 for Middle Click

Example : VbWindow(“Emp”).VbButton(Submit).Click

Submit

2. dbl

Click : which is used for double clicking on a specified object

Syntax : Object  Hierarchy. Click [ x, y [button]] 

0 for Left Click

1 for Right Click

2 for Middle Click

Example : VbWindow(“Emp”).VbButton(Submit).dblClick

3. Set Method : Set method is used mainly to perform on 3 objects i.e

a). Edit box

b). Check Box

c

)

.

R

a

d

i

o

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 7/21

For QTP Realtime Scripts, visit www.ramupalanki.comButton

a) Edit Box : Set method is used for entering any value into an edit

box

Syntax : Object  Hierarchy. Set “value” 

Example :VbWindow(“Emp”).VbEdit(Ename).Set

“ak”

b) Check Box : Set method is used for Selecting/de-selecting the

check box

Syntax : Object  Hierarchy. Set “ON/OFF” 

Example :VbWindow(“Emp”).VbCheckBox(Mstatus).Set

“ON”

c) Radio Button : Set method is used for selecting a Radio Button in a

group

Syntax : Object  Hierarchy. Set 

Example

:VbWindow(“Emp”).VbRadioButton(Location).Set

Emp

Ename :

Mstatus:

Marrie

d

Un

Married

Location:

Hyderabad

Delhi

Chennai

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 8/21

4. Select Method: Which is used for selecting an item in a ComboBox

or List Syntax : Object  Hierarchy. Select “item” 

Example :

5. Set Secure Method: Which is used for setting the encrypted data into the edit box.

* Encrypted string can be generated with help of a tool “password encoder”.

Navigation for password encoder : Start -> Programs -> QTP -> Tools -> Password encoder 

Syntax : Object  Hierarchy. SetSecure “encrypted String” 

Example : *********

6. Activate Method: Which is used for activating a window or a

dialog box Syntax : Object  Hierarchy. Activate

Example :

7. Close Method: Which is used for Closing a window or 

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 9/21

For QTP Realtime Scripts, visit www.ramupalanki.combrowser  Syntax : Object  Hierarchy. Close

8. Type Method: Which is used for performing any kind of keyboard related

operations. Syntax : Object  Hierarchy. Type keyvalue

Example : ggggg

Example : X

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 10/21

Important Methods

RO ( Runtime Object ): Runtime object is the original object that was presented in the application (AUT

TO ( Test Object ) : Test object the Reference of original object stored in the object repository and

used for identifying the original object in the AUT during the execution.

1. Get RO Property : This method is used for getting the Runtime Object property’s value

Syntax : var = Object  Hierarchy. getROproperty(“property name”)

Text

Width etc…..

Note : By using getROproperty method we can avoid the standard checkpoint, because, the check points

will create an “internal file” which is a over burdon the execution and takes the memory to store that files.

Example : Develop the script to click on OK button if it exists.

OK

var = VbWindow(“name”).VbButton(“OK”).Exist : to find the window existence

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 11/21

For QTP Realtime Scripts, visit www.ramupalanki.comIf ( var= ture ) then

var1 = VbWindow(“name”).VbButton(“OK”).getROproperty(“enabled”)

if(var1= true) then

VbWindow(“name”).VbButton(“OK”).Click : *

else

Reporter.ReporterEvent 3, “myreporter”, “OK Button is disabled” : 3=wornin

end if 

Else

Reporter.ReporterEvent 3, “myreporter”, “OK Button doesn’t existing” : 3=wornin

End if 

* This is the only script that we generated by tool and remaining thing is the enhancement to

that script done manually by test engineer.

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 12/21

2. Get TO Property : This method is used for getting the Test Object’s properties value.

Syntax : var = Object  Hierarchy. getTOproperty(“property name”)

Text

Width etc…..

Example :

var = VbWindow(“form1”).VbButton(“ADD”).GetTOproperty(“Text”)

Note : The properties that are learnt during the learning time are called Test Object Properties

Test Object Property = Properties presented in object Repository

+

Properties presented in secret place (smart brain ) if any.

Test object is a Reference of runtime objects which are stored in Object Repository

and in smart brain (if smart brain is enabled).

 Whatever all the Properties Learnt during the learning time are called Test Object Properties.

When with help of Get RO properties its self we can get all the properties in an AUT ? Why Get RO and

Get TO properties?

Get RO property will be used to capture the all the properties’ present values of objects in

AUT during the Learning Time

where as Get TO property will be used to capture the all the properties’ present value o

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 13/21

For QTP Realtime Scripts, visit www.ramupalanki.comobjects in AUT during the execution time.

For example : In a application OK button is disabled by default ( This RO property) but when

entering some data therein the OK button will be enabled( This TO property).

3. Set TO Property : This method is used for Setting the Test Object’s properties value temporarily

during the execution.

Syntax : var = Object  Hierarchy. SetTOproperty “property name”, “Property value”

Text OK

Width etc….. Start …..

Example : for clicking on same button for Start-Stop-Start. Assume that initially the button is named

with Start and want to be Stop when its clicked. And again if its clicked, it should be Start.

1St rename the button name as B1 in Object repository so as to don’t effect other 

buttons. VbWindow(“form1”).VbButton(“B1”).Click

VbWindow(“form1”).VbButton(“B1”).SetTOproperty “text”, “stop”

VbWindow(“form1”).VbButton(“B1”).ClickVbWindow(“form1”).VbButton(“B1”).SetTOproperty “Text”, “Start”

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 14/21

Simple VB Script functions used for Calculation and Comparison :-

CSTR : It is used for converting a value into String

Syntax : CSTR(var1) = CSTR(var2)

CINT : It is used for converting a value into Integer 

Syntax : CINT(var1) = CINT(var2)

CDBL : It is used for converting a value into Decimal value

CBOOL: It is used for converting a value into Boolean value

LTRIM: It is used for Trimming the Left side spaces

RTRIM: It is used for Trimming the Right side spaces

TRIM : It is used for Trimming the Both sides spaces

LEFT : It is used for Getting the Left substring

RIGHT: Syntax : var = Left(string, No. of characters )

It is used for Getting the Right substring

MID Syntax : var = Left(string, No. of characters )

: It is used for Getting the Middle substring

Syntax : var = Left(string, starting character number, No. of 

characters )

LCASE: It is used for converting a string to lowercase

UCASE: It is used for converting a string to uppercase

ROUND: It is used for Rounding a value to its nearest integer.

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 15/21

For QTP Realtime Scripts, visit www.ramupalanki.com

Script :

Action : Action is defined as a set of instructions to perform a specific task.

Test: Test is defined as one or more script files

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 16/21

Data Table Methods

Data Tables are two types 1. Design Time data table 2.

Run Time Data Table

Data table methods are used for performing the operations on the Runtime Data table during the execution.

• All Data Table Methods are used in Runtime data table ONLY i.e we can’t do any thing withDesign time data table.

· For every action a corresponding Sheet will be created in both data tables but only one

Global sheet for each data table.

· In order to maintain test data clearly, simply and user friendly we Maintain each sheetfor each corresponding action.

· Sheet can be inserted along with action only.

· If you want to import data to Runtime data table , you need to add sheet manually in the same.

Local Sheet : In local sheet the focus will be on 1st row itself only

Global sheet : In global sheet for every iteration the focus need to change on next row and so on.

Methods :-

1. AddSheet() :- It is used for adding an extra sheet to the Run Time data table

Syntax : Datatable.AddSheet “Sheet Name” 

2. DeleteSheet() :- It is used for deleting a specified sheet from the Run Time data table

Syntax : Datatable.Deletesheet “sheet name” 

3. Import() :- It is used for importing the data presented in all the sheets in a xl file to the RTDT

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 17/21

For QTP Realtime Scripts, visit www.ramupalanki.com

Syntax : Datatable.import “path of the .xls file” 

4. ImportSheet() :- It is used for importing the data presented in a specified sheet in the xl

file to the specified sheet in Run Time Data table.

Syntax : datatable.ImportSheet “path of the xl file”, Source sheet ID, Destination Sheet ID

5. Export() :- It is used for exporting the data presented in Run time data table to a specified laction.

Syntax : datatable.Export “path of the location with a file name .xls extension” 

6. ExprotSheet() :- It is used for exporting the data presented in a specified sheet in Run time

data table to a specified location

Syntax : datatable.ExportSheet “Path of the location with a file name .xls extension” , Sheet ID to be exported 

7. SetCurrentRow() :- It is used for making the QTP focus on a specified row

Syntax : datatable.SetCurrentRow(Row number)

8. SetNextRow() :- It is used for making the QTP focus on the Next row of Currently focused row

Syntax : datatable.SetNextRow 

9. SetPreRow() :- It is used for making the QTP focus on the previous row of the currently focused row.When this method executes, the cursor will go to the last row of the table and moves

upward one by one row till it reaches to 1st row in the table.

Syntax : datatable.SetPrevRow 

10. GetSheet() :- It is used for making the QTP focused on a specified sheet.

Syntax : datatable.GetSheet( Sheet Id)

11. Value() :- It is used for getting a value from a specified sheet, specified column and currently focused row.

Syntax: datatable.value(“column name”,sheet Id)

12. GetRowCount() :- It is used for getting the row count of the global sheet by default. If at all one wants

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 18/21

the row count of a specified sheet , then, First he needs to focus on the sheet and

then get the row count.

Syntax 1 : variable=datatable.GetRowCount 

Syntax 2 : variable= datatable.GetSheet.GetRowCount 

Example : For add data sheet, import data to datasheet, ADD the two values, pass the result to data sheet, export

the data sheet to log folder.

  Open the calculator application

First we need to Capture all objects properties into Object Repository

Open the QTP

Go to Tools

Select opting Object Repository. An object repository will be opend

Click on ‘Add Objects’ button, Point to calculator application main window

‘Object selection – Add to repository’ window will appear 

Click on OK

Select option as ‘selected object and all its direct children’ on newly opened window

Click on OK

Click on OK

So that we have captured all the objects properties to Object Repository.

Write the script ( copied from test pane )

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 19/21

For QTP Realtime Scripts, visit www.ramupalanki.com' Create a sheet in Run time data table

by name Ak datatable.AddSheet"Ak"

' Import the data from TestData folder ( which we have created while design the Frame

work) ' path, 1= global sheet in RTDT and 3= Just created Sheet i.e AK in RTDT

datatable.ImportSheet"C:\Documents and Settings\AK\Desktop\fl_application\TestData\td1.xls",1,3' counting the number of rows and assigning to a variable

n=datatable.GetSheet(3).GetRowCount

'taking FOR loop to check with all the rows

data For i=1 to n

' focusing to 1st row

datatable.SetCurrentRow(i)

'parameterizing val1 and val2

' 3= Ak sheet in RTDT

VbWindow("Form1").VbEdit("val1").Set Datatable("val1",3)

VbWindow("Form1").VbEdit("val2").Set Datatable("val2",3)

VbWindow("Form1").VbButton("ADD").Click

' assigning expected value of 3 sheet in

RTDT expval = datatable.Value("ev",3)

' capturing actual value in result field of AUT

actval = vbwindow("Form1").VbEdit("res").GetROProperty("text") '

comparing the expected value and actual value

If (expval = actval ) then

' Passing the result to sheet # 3 in res

column as Pass datatable("res",3) =

"Pass"

else

' Passing the result to sheet # 3 in res column as Fail

datatable("res",3) = "Fail"

End If 

Next

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 20/21

' Exporting the result to Log folder 

' This is called creating Log files

8/8/2019 Method Method is Some Thing Which is Used By

http://slidepdf.com/reader/full/method-method-is-some-thing-which-is-used-by 21/21

For QTP Realtime Scripts, visit

www.ramupalanki.comdatatable.ExportSheet "C:\Documents and

Settings\AK\Desktop\fl_application\TestData\td2.xls",3 ' Deleting the added data sheet

datatable.DeleteSheet "Ak"

Run

Analyze the result

-: The End :-

Pls. leave your feed back (both +ve and –ve ) at [email protected] n