Sie sind auf Seite 1von 34

QTP Interview Questions

FAQ in QTP

This topic discusses on some of the very useful Interview Question.

1. What are the very important prerequisite to be known before working with QTP ?

Quick Test Professional support many scripting Language, but this blog discusses QTP with
VBScript.

Hence to work with QTP one require hands on Experience on

• Basic knowledge in VBScript


• Basic knowledge in Excel
• Good knowledge in Manual Testing (Understanding Application)
• Basic knowledge in any database (At least DDL and DML)

2. How does QTP recognize object in an Application ?

QTP is a very fascinating tool and it tries to recognize as much object in Application as possible.
The Process of identifying object happens as one given below

QTP’s object identification concept is based on 4 types of properties and an ordinal identifier.

Types of properties:

<!--[if !supportLists]-->· Mandatory properties<!--[endif]-->

<!--[if !supportLists]-->· Assistive properties<!--[endif]-->

<!--[if !supportLists]-->· Base Filter properties<!--[endif]-->

<!--[if !supportLists]-->· Optional Filter properties<!--[endif]-->

A test engineer can specify list of mandatory properties, assistive properties, base filter
properties, optional filter properties and Ordinal Identifier

QTP will learn the information in the following way: -

First of all QTP will learn all the specified mandatory properties and then think whether
these properties are sufficient to identify the object uniquely. If it feels sufficient it will stop
learning. Otherwise it will learn the 1st assistive property. Then once again think whether all the
properties are sufficient for identifying the object uniquely. If at all it feels sufficient it will stop
learning otherwise it will learn the 2nd assistive property and then think again whether all these
properties are sufficient for identifying the object uniquely. This process continues till the QTP get
satisfied or up to the end of the assistive properties list.
If still QTP feels not satisfied then finally it will learn the ordinal identifier. All the
properties learnt during this process will be stored in the object repository.

If at all the smart identification option is selected then the QTP will learn the base filter properties,
optional filter properties along with the mandatory properties and stores the base filter properties
and optional filter properties separately and secretly and then continues with the same procedure
as above.

3.What is Smart Identification ?

Smart Identification is a mechanism provided by QTP, which is used for


identifying the objects even though some properties are dynamically
changed.

4. What is Ordinal Identifier ?

The ordinal identifier assigns the object numerical values that indicate its order relative to
other objects with an otherwise identical description

There are 3 types of ordinal identifiers.

1. Location

2. Index

3. Creation Time

1. Location: If at all the Location is selected as an ordinal identifier then the QTP will generate the
sequence of numbers from 0,1,2,… based on the sequence of the objects located in the
application.

2. Index: If at all the index is selected as an ordinal identifier then the QTP will generate the
sequence of numbers from 0,1,2,… based on the sequence of the programs of the corresponding
objects.

3. Creation time: If at all the creation time is selected as an ordinal identifier then the QTP will
generate the sequence of numbers from 0,1,2,… based on the loading time of a web page.

5. What is Object Repository ?

Object Repository (OR) is used to store all the recorded Applications Objects
(Property and Value) in QTP.

Each time while Identifying an Object QTP checks OR and then identifies the
Object in Application.

OR contains all the Objects Properties and Values


E.g. For a checkbox recoreded with QTP, the OR contains

Class Name = “Checkbox”

Name = “Yes/No”

Here Class Name is called as Property and “Checkbox” is its associated Value.

6. What happen if QTP does not recognizes Object in Application ?

There Needs following Steps to be taken

1. Check for Necessary Plug-ins for QTP.

2.Use Smart Identification mechanism.

3.Use descriptive programming.

7. What is the Purpose of Environment Variable ?

Scenario:

In order to declare an Variable with value say

OS=”Windows XP”

Flag = 3

to be accessed throughout the Test (Including all the Actions within the Test) we need to declare
these variable in all the Action and then access them in Scripts.

What happen if there are multiple Variables whose values are same and does not change and we
require them in all Actions ?.

Then there comes what is called as Environment Variable.

Using User Defined Environment Variable we can access all Variable and its values throughout
the test without needing to declare them.

In order to declare Environment Variable go to

File –> Settings –> Environment Tab –>select Variable type as “User Defined” and add the
Variable say “myOS” as Name and Value as “WindowsXP” (Remove quotes)

Now in Expert View write the following coding snippets

myValue = Environment(”myOS”)
msgbox(myValue)
Message box will show the Value “Windows XP”

8. What is Recovery Scenario and where do I use that ?

Recovery Scenario is useful while the Test gets interrupted by External Events like Pop-up
window, object state, Test run error, application crash.

Pop-up window: quick test detects a pop-up window and identifies it according to the window
title and textual content.

Object State: Quick test detects a specific test object state and identifies it according to its
property values and the property values of all its ancestors.

Note that an object is identified only by its property values and not by its class.

Test run error: Quick test detects a run error and identifies it by a failed return value from
method.

Application crash: Quick test detects an application crash and identifies it according to a
predefined list of applications.

In order to cope the above mentioned Events Recovery Scenario is used.

9. What are the Recording Modes in QTP ?

There are 3 modes of Recording Application in QTP they are

1. Normal Recording
2. Analog Recording
3. Low Level Recording

Normal Recording

This mode is the default and takes full advantage of the QuickTest test object model, recognizing
the objects in your application regardless of their location on the screen.

Analog Recording

Enables you to record the exact mouse and keyboard operations you perform in relation to either
the screen or the application window. In this recording mode, QuickTest records and tracks every
movement of the mouse as you drag the mouse around a screen or window.

Low Level Recording

Enables you to record on any object in your application, whether or not QuickTest recognizes the
specific object or the specific operation. This mode records at the object level and records all run-
time objects as Window or WinObject test objects. Use low-level recording for recording in an
environment or on an object not recognized by QuickTest.
Thanks “Source: Mercury QTP Help doc”

10. What is Shared Object Repository and when is it Useful ?

There are situation in Real time scenarios where multiple people will be working around with QTP
with same test and hence they will be updating the Object Repository (OR).

During that scenario we can use the Shared Object Repository to store the Object of the
Application and hence concurrent modification in the OR can be done by multiple people at a
time.

Showing newest posts with label QTP. Show older posts


Showing newest posts with label QTP. Show older posts

Sunday, June 15, 2008

QTP Tutorial 1: Learning Recording

For any suggestions or any topic you want to include


in this blog or even discuss, please email me on
expert.qtp@gmail.com
Lets start recording with the mercury sample application FLIGHT.

We will begin with a simple test like the "Hello World" program with which we start learning any
programming language.

1) First of all click on Record toolbar button ( or Automation menu --> Record or press F3). when we
click on Record, "Record and Run Settings" window opens up. Go to "Windows Applications" tab and
choose first option "Record and run test on any open windows based application." and click on ok.

2) Open Flight application (Start -->All programs -->QuickTest Professional --> Sample Applications -->
Flight)

3) Type Agent name as "Shree" (You can enter any, but must be 4 characters or more) and enter
password as "mercury".
4) In the flight reservation window that opens up:

a) In the Flight Schedule area, in Date of Flight enter tomorrow's date in mm/dd/yyyy format.( I used
tabs to move to next fields)
b)In Fly From enter Denver
c)In Fly To enter London
d) Click on Flights button which is on the right hand side of "Fly To".
Let the default option be selected in the Flights Table.
e) Click ok
f)In the name field enter your name. It will fill rest of the required information by itself.
g) Click on insert order and after the order is inserted
h) Click on File --> exit.

5) Now you have recorded your first script. You can click on the expert view tab to see the script which
QTP has recorded for you automatically.

6) Click on run from Automation Menu (or press F5) to open up run dialog box.

7) Go to the "Results Location" tab, and below "write run results to", in "new run results folder" radio
button- let it be the default option --C:\Program Files\Mercury Interactive\QuickTest
Professional\Tests\Test1\Res1(you can also change it)

8) click on ok.

This will run you earlier recorded test and show you the results.

But we have to go a long way. This is just the beginning.

Labels: Automated testing, QTP, Recording

Posted by QTP Expert at 2:41 AM 1 comments

QTP Tutorials 2 - Using Data Table


Lets use data table:
There are two types of data tables Design time and Run time:

Design time data table is what you see in the main QTP window and run time data table you can see only in the test
results window. Design time data table is always created before running the test while run time data table is generated
after execution of the test.

1) Open new test (Ctrl+N)

2) We will click on record toolbar button ( or Automation menu --> record or press F3). when we click
on record, "Record and Run Settings" window opens up. Go to "Windows Applications" tab and
choose first option "Record and run test on any open windows based application." and click on ok.

3) Open Flight application (Start-->All programs-->QuickTest Professional->Sample Applications--


>Flight)

4) Type Agent name as "Niyati" (you can enter any, but must be 4 characters or more) and enter
password as "mercury".

5) In the flight reservation window that opens up:

6) Click on File-->exit. Click Stop to stop the recording.

7) In the keyword view you will see four headings- Item, Operation, Value, Documentation. Under
Value click on Kumar and on the right hand side of Kumar you will see a small icon, just click on that
(or press ctrl + F11), The "Value Configuration Options" dialog box opens. In that dialog box click on
parameter radio button and select Data Table from there. In Name field enter any variable name (I
entered 'username'). Let all other be the default options in this dialog box and click on ok.

8) QTP will add username column in the data table (bottom, left hand side) with 'Niyati' as the first
value.

9) Now enter more values in the username column, manually. I entered 'Varun' and 'Tanya' in 2nd and
3rd column respectively.

10) Save the test. (File-->Save).

11) Now run the test. (follow same steps as we did earlier).

12) If the test ran successfully, in the Results summary window on the left hand side you will see three
iterations (because we added 3 variables in the 3 rows of a data table). Expand 1st iteration, it will
show action summary for that iteration, expand the action summary, it will show Login, Expand the
login. Click on the first option under it "Agent Name: SetText". On the right hand side it will show 1st
variable name under details.

13) Similarly you can look for 2nd and 3rd.

Labels: Automated testing, DataTable, QTP


Sunday, June 15, 2008

QTP Tutorials 3 - Accessing Data Table values through Script

What if we want to write a short script that accesses values from the data Table.

1) Make sure that QTP (with a new blank test) and a blank notepad is open.

2) In the Data Table below write a, b, c in the first column A.

3) Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to
"Windows Applications" tab and choose first option "Record and run test on any open windows based
application." and click on ok.

4) Just highlight the notepad and write 'a' on it.

5) Click on Stop so as to stop recording.

6) In the expert view your script will look like this:

Window("Notepad").WinEditor("Edit").SetCaretPos 0,0

Window("Notepad").WinEditor("Edit").Type "a"

7) We have to make it look like this:

rc = DataTable.Value("A", dtGlobalSheet)

msgbox rc
Window("Notepad").WinEditor("Edit").SetCaretPos 0,0

Window("Notepad").WinEditor("Edit").Type rc

8) Save the Test.

9) Run the Test again with a blank Notepad open. It will enter all the three values from Data Table into
the Notepad.

Sunday, June 15, 2008

QTP Tutorials 4 - Standard Checkpoint


Checkpoints cannot be added manually, they are inserted using QTP's interface. Results of the
checkpoint can be viewed in the Test Results Window.

Checkpoint information is stored in the Local Object Repository. It is in the Resource.mtr file which is in
the action folder (if you created checkpoint in action1 then it will be action 1 folder under the folder in
which you are saving the test/script, if you created checkpoint in action 2 then it will be action 2 folder
and so on) .

In the expert view, on any blank line type Checkpoint and put "(". As soon as you put the starting
bracket it will show all the checkpoints you have used in the test.

Now we will start with checkpoints. I will try to show easy to understand example of each and every
checkpoint.

Lets start with simple example of standard checkpoint which checks a variety of objects such as
buttons, radio buttons, combo boxes etc. Standard checkpoints are supported for all add-in
environments

1. Open a blank test.


2. Make sure that Flight application is open.
(Now only QTP with blank test and Flight application should be open).
3. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go
to "Windows Applications" tab and choose first option "Record and run test on any open
Windows based application." and click ok.
4. Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).The mouse pointer
will become hand and QTP will be minimized.
5. Click on the "Flights..." button which is on the Right Hand Side of the "Fly To" combo box in
the Flight application.
6. It will open "Object Selection - Checkpoint Properties" window (with WinButton:FLIGHT
highlighted). Click ok.
7. It will open checkpoint properties window. (only one property will be checked in it i.e. 'enabled'
with a value of False.)
8. Click ok. Click on Stop in order to stop the Recording.
9. Save the test.

This is a small test in which we have used standard checkpoint and captured the disabled button on
the Flight application. Now we can run the test in two ways to see how it fails and passes the results of
the checkpoint.

To see a pass test result:

Make sure that this test and Flight application is open. Click on run.

It will Run the test and show you the result as pass.

To see a Fail test result:

Make sure that this test and Flight application is open.

In the Flight application enter the Date of Flight, Fly From and Fly To fields and nothing else. (The
reason for doing this is that it will enable the 'Flight...' button)

Click on run in order to run the test.

It will Run the test and show you the result as Fail. This is because QTP was looking for a disabled
'Flight...' button for which it recorded the information at the record time, but now since the button was
enabled at run time, so it failed.

This will help you in understanding the standard checkpoint in QTP more deeply.

Sunday, June 15, 2008

QTP Tutorials 5 - Page Checkpoint


Page checkpoint:It is for web applications only.Common things to check with this are load time, broken
links etc.
1. Open a blank test.
2. Make sure thathttp://www.google.co.in/ is open.(Now only QTP with blank test and
www.google.co.in should be open.)
3. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go
to "Web" tab and choose first option "Record and run test on any open browser." and click ok.
4. Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).
5. The mouse pointer will become hand and QTP will be minimized.
6. Click anywhere on the white space on the Google.co.in page.
7. It will Open "Object Selection - Checkpoint Properties" window. Click on 'Page : Google'
option which has a page icon on left of it with right corner of the page slightly folded.
8. Click ok.
9. A 'Page Checkpoint Properties' window opens up. Let all the options be default. Click ok.
10. Click on Stop in order to stop the Recording.

In the Expert view it will add just one line:

Browser("Google").Page("Google").Check CheckPoint("Google")

We will explore this line later on.

I ran this test by opening www.google.co.in in offline mode (not on internet). It recorded the following
properties:

Property Name Property Value


load time "0"
number of images "2"
number of links "20"

Here it shows the load time as 0 because I did not open Google at the time of running the test, it was
already open.

When you run it, in the results window, on left hand side, it will show (when every option is expanded):

Test Checkpoint-page Summary (where Checkpoint-page is the name with which I saved the test

Run-Time Data Table


Checkpoint-page Iteration 1 (Row 1)
Action1 Summary
Google (This will be the browser)
Google (This will be the Page)
Checkpoint "Google"
If you run this test on www.google.com it may fail.

Sunday, June 15, 2008

QTP Tutorials 6 - Bitmap Checkpoint


Now we will look at the bitmap checkpoint which is different from the image checkpoint.

Make sure that QTP and the Flight application are open.

STYLE A

1. Open a blank test.


2. Click on Record. When we click on Record, "Record and Run Settings" window
opens up. Go to "Windows Applications" tab and choose first option "Record and
run test on any open windows based application." and click Ok.
3. Go to Insert (menu)->Checkpoint->Bitmap Checkpoint
4. Click on the "Fly To" combo box.
5. "Object Selection- Bitmap Checkpoint Properties" window opens up. I will have
"WinComboBox:Fly To" highlighted. Click ok
6. It will open "Bitmap Checkpoint Properties" window.
7. Change the "Checkpoint timeout" at the bottom of the window to 0 seconds, so that we will
have no wait time while running the test.
8. Click ok.
9. Click stop to stop recording the test.

STYLE B

Above, after 3rd point, instead of clicking on the "Fly To" combo box, click somewhere in the empty
space above the "Fly From" Combo box but below the line, i.e. in the "Flight Schedule" area.

"Object Selection- Bitmap Checkpoint Properties" window opens up. It will have "WinObject:Flight
Schedule" highlighted. Click ok

It will open "Bitmap Checkpoint Properties" winodow. This time it will have "Flight schedule" area
instead of just the "Fly To" combo box.
Now click on the "Select Area..." button. Mouse pointer will change so that you can select any area by
dragging. Just select "Fly From" combo box by dragging.

Change the "Checkpoint timeout" at the bottom of the window to 0 seconds. so that we will have no
wait time while running the test.

Click ok.

Click stop to stop recording the test.

Now you can run the test it will pass. To see how it stores the results, just fail the test. If you have
recorded in the style A then just select any value in the "Fly To" combo box and then run the test. In
the result window on the left hand side when you click on Checkpoint "Fly To:", it will show you the
expected bitmap and actual bitmap on the right hand side. (note: it will show that only in case of Failed
result

Labels: Automated testing, Checkpoint, QTP

Sunday, June 15, 2008

QTP Tutorials 7 - Image Checkpoint


Lets see the Image checkpoint.

Open a blank test.

On your system under My Documents, there will be a folder named My Pictures, under this you will
will find a folder- Sample Pictures( containing 4 pictures - Blue Hills, Sunset, Winter, Water lilies)

We will run this test with one of the image there- Sunset.

Go to My Documents->My Pictures-> Sample Pictures and right click on image


named 'Sunset' and open it with internet explorer.
Now only a new blank test and internet explorer with this image should be open.

Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Web"
tab and choose first option "Record and run test on any open browser." and click on Ok.

Go to Insert (menu)->Checkpoint->Standard Checkpoint(or press F12).The mouse pointer will


become hand and QTP will be minimized.

Click on the image which is opened in the explorer.

It will open 'Object Selection Checkpoint Properties' window with Image: Sunset highlighted. Click Ok.

It will Open 'Image Checkpoint Properties' Window. In this window just uncheck all the property values
like href, html tag etc and only check last property which is src.

Rest every thing will be default. Click OK.

Click stop to stop recording the test.

In the expert view it will just add one line Browser("file:///C:/Documents%20and


%20S").Page("file:///C:/Documents%20and%20S").Image("Sunset").Check CheckPoint("Sunset")

If you run it with that image open in internet explorer it will pass. This test is not intelligent enough. It is
just checking that the image in the explorer is in the same location in which it was when the test was
recorded and its name is Sunset. If you change the name of some other picture in that folder to Sunset
and run the test with that it will also pass.
In this way you can test for some or all the properties of the image which it showed in the 'Image
Checkpoint Properties' Window.

Labels: Automated testing, Checkpoint, QTP

Sunday, June 15, 2008

QTP Tutorials 8 - Text Checkpoint


Now we will look at the Text Checkpoint:

Open a blank test and a web page in offline mode like this below:

1. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go
to "Web" tab and choose first option "Record and run test on any open browser." and click on
ok.
2. Go to Insert (menu)->Checkpoint->Text Checkpoint.The mouse pointer will become hand
and QTP will be minimized.Click on the first paragraph (which starts with-The page you are
looking..) of that web page.
3. "Text Checkpoint Properties" window opens up. It will show the text to be checked in
"Checkpoint Summary" area in red color and also show in blue color the text which is
displayed before and after the selected text.
4. Click on Configure -here you can change your selected text, change before and after text and
so on, but for now just click ok. At the bottom of the "Text Checkpoint Properties" window
change 'Checkpoint timeout' to 0 seconds. Again Click ok to come out of "Text Checkpoint
Properties" window.
5. Click on stop in order to stop recording.

Run the test and when it is passed just go to the results window and on the left hand side just expand
every option and click on last option Checkpoint "Cannot find server". On the right hand side it will
show you the details. Try to understand those.

Labels: Automated testing, Checkpoint, QTP


Sunday, June 15, 2008

QTP Tutorials 9 - Table Checkpoint

In this tutorial we will look at a table Checkpoint just to get familiar with it.

Open a blank test and also open a website http://www.editorial.co.in/software/software-testing-life-


cycle.php" in offline mode

This website has a table at the bottom of the page.

Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Web"
tab and choose first option "Record and run test on any open browser." and click on ok.

Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).

The mouse pointer will become hand and QTP will be minimized.

Click somewhere inside the table.

"Object Selection - Checkpoint properties" window opens.

Select "WebTable: Software Testing Life Cycle" which has a table icon on its left, where "Software
Testing Life Cycle" is the name of the table.

Click ok.
'Table Checkpoint properties' window opens. It will show all the rows and columns of the selected
table. This time we will not do any extra setting. Just change the Checkpoint timeout at the bottom of
this window to 0 seconds and click ok .

Click stop in order to stop recording.

Run the test and analyze the results in the result window, mainly the checkpoint results to see how
QTP verifies the result. We will manipulate test results in later tutorials.

Labels: Automated testing, Checkpoint, QTP

Posted by QTP Expert at 1:30 AM

Sunday, June 15, 2008

QTP Tutorials 10 - Checkpoint Return Value


We will use the Standard Checkpoint which we did in tutorial 4.

Open that test that contains the standard Checkpoint.


In the expert view of the test you will see only one line i.e.

Window("Flight Reservation").WinButton("FLIGHT").Check CheckPoint("FLIGHT")

Now we will make some changes in this one line so that it can return some value.

NOTE: Checkpoint always returns a value, it depends on us whether we capture it or not.

Lets now capture it.


Declare a variable and catch the return value in that variable:
Dim return
return = Window("Flight Reservation").WinButton("FLIGHT").Check CheckPoint("FLIGHT")
msgbox (return)

One thing more we need to do here is that we have to enclose Checkpoint ("FLIGHT") in brackets.
So the final version looks like this:

Dim return
return = Window("Flight Reservation").WinButton("FLIGHT").Check (CheckPoint("FLIGHT"))

msgbox (return)

It can return either true or false i.e. a boolean value. If it passes, it will return true else it will return false

Labels: Automated testing, Certification, Checkpoint, QTP

Posted by QTP Expert at 1:25 AM

0 comments:

June 15, 2008

QTP Tutorials 11 - Actions


In this tutorial we will see how to use more than one action in a test and how to call one action from
another with in the same test.

Open a blank test. By default it will have Action1 in it (make sure you are in the keyboard view).

Make sure that Action1 is selected/highlighted and click on the Expert View tab.
In the Expert View type:
msgbox ("my action 1")

Again when you go to keyword View and expand Action1 it will show you function call under it.

In that keyword View itself go to Insert (Menu) ->Call to New Action. 'Insert Call to New Action' Dialog
box opens with Action2 as a default name of a new action. By default it will be added at the end of the
test as this radio button is selected in the location area.

Click ok.

It will add Action2 to your test.

Make sure that Action2 is selected and click on the Expert View tab.

In the Expert View type:


msgbox ("my action 2")

Similarly insert a third Action.

After third action is added, select Action1(keyword view), right click on it and choose 'Action
Properties'.

In the Action properties window that opens, check the 'Reusable action' checkbox at the bottom.

Click ok.
Now again highlight Action3 right click on it and choose 'Insert Call to Existing action'.

'Select action' dialog box appears. In this dialog box in the 'action' dropdown box it will have Action1 by
default since we made only that action as reusable.

Just click ok.

In the keyword View where you can see all the three actions, make sure against Action3 it shows "Call
to Action1 action" under Documentation.

Run the test. Three message boxes appear in succession showing 'my action 1', 'my action 2', and
again 'my action 1'.

Labels: Automated testing, Certification, QTP, QTP Actions

Posted by QTP Expert at 1:23 AM

Sunday, June 15, 2008

QTP Tutorials 12 - Script to create file


Now lets do some kind of processing with file system e.g. working with text, excel, word etc files from
within the QTP.

For this tutorial you need to know VBScript FSO (File System Object).

The main purpose of the FSO is to access the file system of the computer.

File System Object model is:


Drive
|
Folder
|
File
|
Textstream

or some people make it like this:

Drive
|
Folder
|
Folders
|
File
|
Files
|
Textstream

These above objects have methods and properties. With these above objects you can obtain and work
with the information about drives, folders, files etc like creating a new file, opening a file, writing into a
file and much more.

Here we will see a very simple example how to create a text file from within QTP.

Dim fso, new_file


Set fso = createobject("scripting.filesystemobject") // an instance of filesystemobject is being created
here. After an instance (fso) is created then we can use the methods (like createtextfile, CreateFolder
etc) with that objects instance.

Set new_file = fso.createtextfile("c:\testfile.txt", True) //createtextfile is a


method to create a file and after creating a file it returns a TextStream object
that can be used to read from or write to the file.
new_file.writeline("hello world!")
new_file.close

Just write the above text in the expert view of a new blank test and run it. A new text file (testfile.txt)
will be created with "hello world!" written in it.

Try to change the extention of testfile.txt to testfile.doc and see what happens.

Much more to come, keep on reading guyz!!!


Labels: Automated testing, Certification, QTP

Posted by QTP Expert at 1:08 AM

2008

QTP Tutorials 13 - Regular Expression


Objects and text strings with varying (changeable) values or we can say dynamic values can be
identified by QuickTest using Regular expressions.

Regular expressions can be used:

• To define property values of an object.


• To parameterize a step.
• To create a checkpoint with changeable values.

Important points regarding Regular expressions:

You can use regular expressions only for values of type string.

When any special character in a regular expression is preceded by a backslash (\), QuickTest
searches for the literal character.

You can define a regular expression for a constant value, a Data Table parameter value, an
Environment parameter value, or a property value in a programmatic description.

For more common options to create Regular Expressions, see QTP User Guide.

Instead of writing more about QTP regular expressions, lets quickly jump to examples.
Below you will find examples.

QTP Regular Expression Example 1

[This is just an example using Yahoo mail inbox. Your inbox unread mails may differ from the one
shown in this example]

1. Launch QTP and open a new test.


2. Open Internet Explorer.
[Now we have QTP with a blank test and Google open.]
3. Click on Record in order to start recording.
4. Copy and paste this URL (http://mail.yahoo.com) in the browser's address bar to open Yahoo mail
login.
5. Type your user name and password to login to Yahoo mail.
6. When Yahoo mail is open, click on the Inbox link as shown in the screenshot below.[ Note: The
Inbox can contain any number of mails. At any given point of time, Inbox(5) means 5 unread mails]
7. Click on Stop in order to stop recording. Then my recorded code looks like this:

Browser("Browser").Page("Page").Sync
Browser("Browser").Navigate "https://login.yahoo.com/config/login_verify2?&.src=ym"
Browser("Browser").Page("Yahoo! Mail: The best").WebEdit("login").Set "piyush
Browser("Browser").Page("Yahoo! Mail: The best").WebEdit("passwd").SetSecure
"4801a2cbf793b46aad67194b5cbc961c091f"
Browser("Browser").Page("Yahoo! Mail: The best").WebButton("Sign In").Click
Browser("Browser").Page("Yahoo! Mail - piyush@yahoo.com").Link("Inbox (6)").Click

Now if you don't check any mail in your inbox and log out and then again run this code it will work fine.

But if you check any mail like if I check one mail in my inbox then it will be Inbox(5), then if I run this
code it will fail because the link has changed from Inbox(6) to Inbox(5) and shows the below
mentioned error.

"Cannot identify the object Inbox(6) (of class Link). Verify that this object`s properties match an
object currently displayed in your application."
Now we will change the above code with the help of regular expression so that it will work even if there
is only one unread mail.

In QTP go to Resources (menu) ->Object Repository.

Object Repository window will open. Select the object "Inbox(6)". Click on the label Inbox(6) inside
Value column and then click on "<=>" button which will appear.

When you click on the button, it will open 'Value Configuration Options' window. On this window click
on Regular Expression check box. When you click on checkbox it will show warning . Just click on Yes.

Now in the Constant text box inside the displayed window( what I have entered "Inbox \([5-6]\)" and
click Ok and close Object Repository window.

This Regular Expression setting which we have done works for inbox unread mails between 5 and 6
e.g. if your inbox says inbox(5) or inbox(6).

Run the test. It passes for me because I had 5 unread mails in my inbox (inbox(5)).

You can do this setting according to your convenience e.g. [1-5] for unread mails between 1 and 5 and
so on.

Labels: Automated testing, Certification, QTP

Posted by QTP Expert at 12:34 AM

Monday, October 27, 2008

How to View Object Properties by using Object Spy


This short tutorial guides you to a method by which you can view the Object Properties & Methods with
the help of Object Spy in QTP.

We can view the Properties and Methods of any object in an open application with the help of Object
Spy pointing hand mechanism. As we move the pointing hand over the objects in the application, िठर
details get displayed in the Object Spy.

These details displayed in the Object Spy are the hierarchy tree of the test object, its properties and
values, and the methods associated with the object. For methods, the syntax is also displayed.

Steps to view test object properties or methods:


Step-1: Open the application to the page containing the object on which we want to spy say
google.com.

Step-2: Choose Tools > Object Spy or click the Object Spy toolbar button to open the Object Spy
dialog box and display the Properties tab.

Or click the Object Spy button from the Object Repository dialog box.

Step-3: Select the details we want to view for the object.

• Click Run-time Object Properties or Test Object Properties radio button.


• To view the object’s available methods and syntax, click the Methods tab. Properties tab is
displayed by default, enabling us to view the object’s properties and values.

Step-4: In the Object Spy dialog box, click the pointing hand which is displayed on top. QuickTest
remains hidden. As we move the pointing hand over the test objects in our application, the test objects
get highlighted, and we can view their test object properties or methods in the Object Spy dialog box.
We can also view their parent objects in the object hierarchy tree area of the Object Spy dialog box.

Step-5: Highlight or click the object whose properties or methods we want to view। The Object Spy
displays the object hierarchy tree and the properties or methods of the object that is selected within the
tree.
Step-6: Click the object whose associated methods we want to view. The Object Spy displays the
object hierarchy tree and details for the selected object according to our selection.

Step-7: To view the properties or methods of the test object, click the Test Object Properties radio
button. To view the properties or methods of the run-time object, click the Run-time Object Properties
radio button.

Step-8: If we want to view properties, values, or methods for another object within the displayed tree,
highlight or click the object in the tree and select the relevant options, as described in step 3 above.

Step-9: If we want to copy an object property or value, or a method’s syntax to the Clipboard, click the
property, value, or method to highlight it. The value gets displayed in the selected property / value or
method syntax box which is located above the Description box. Highlight the text in the box and use
CTRL + C to copy the text to the Clipboard or right-click the highlighted text and choose Copy from the
menu.

Keywords: QTP, Quicktest Professional, QTP Object Spy, QTP Tutorials

Posted by QTP Expert at 1:34 PM

0 comments:

Saturday, March 13, 2010

QTP Tutorial Database Checkpoint


Lets try out our hands on Database checkpoint: using Oracle 9i

First of all you have to connect oracle 9i to QTP 9.(before doing any recording)
• For this go to Insert -> Checkpoint -> Database Checkpoint.

• A Database Query Wizard opens.

Select ' Specify SQL statement manually' from the Query definition area. Click Next.
• Here click on 'Create' button which is on the right of "Connection String:" It will open 'Select

Data Source' window. Click on 'Machine Data Source' Tab


• Click on New Button.

• 'Create New Data Source' window opens.

• Select 'User Data Source' from Select a type of data source. Click Next.

• It will show all the data source drives it could find.

• Select Oracle (on my machine it was 'Oracle in OraHome9'). Click Next. Click Finish.

• It will open 'Oracle ODBC Driver Configuration' window.

• Enter 'Data Source name' ( I entered "oracle")

• Enter 'description' (I entered "SQL")

• Select 'TNS Service Name' ( I selected 'DB02', my oracle database name) from combo box.

• Enter userid (I used SCOTT).

• Click 'Test Connection' Button. It will ask for a Password. Enter your password for Oracle.

• If successful it will show 'Testing Connection' window with 'Connection Successful' written on

it.

This completes our task of Connecting QTP with Oracle.

Now we will record a test.

• Open a blank test.

• Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go

to "Windows Applications" tab and choose first option "Record and run test on any open
Windows based application." and click on ok.
• Go to Insert (menu)->Checkpoint->Database Checkpoint

• A 'Database Query Wizard' opens.

• Select ' Specify SQL statement manually' from the Query definition area. Click Next. Click

Create.
• Go to 'Machine Data Source' Tab

• Select Oracle from data source name. Click Ok. It will open 'Oracle ODBC Driver Connect'.

• Enter password. Click ok

• It will come to Database Query Wizard window with 'Connection String' field filled with:

"DSN=oracle;UID=SCOTT;PWD=TIGER;DBQ=DB02;DBA
=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;
LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;
MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;"
• In the SQL Statement area type "select * from emp;". Click Finish.

• It will open 'Database Checkpoint Properties' window with the result of the query. Click Ok.

• Click Stop in order to stop the Recording.

• In the Expert View, it just adds one line "DbTable("DbTable").Check CheckPoint "DbTable")"
This is the simplest database checkpoint example.

Now run it.

Click on Run. ( we don't need to open any other window or application to run this as our Oracle is
running at the back end as a service - default way in which it was installed- nothing special.)

When it is passed it will show following in the Result window:

Test Checkpoint-database Summary (where Checkpoint-database is the name with which I saved the
test)
Run-Time Data Table
Checkpoint-database Iteration 1 (Row 1)
Action1 Summary
DbTable
Checkpoint "DbTable"
( when you click on this, in details it will show checked 112 cells (in your case number of cells may
differ). It means if you go to the oracle and add or delete any row and run this test again it will fail.)

Wednesday, October 21, 2009

QTP Tutorial: Moving mouse to a particular object


Sometimes its required to place your mouse cursor on an object in your application and then perform
some operation like clicking that object or even right clicking. I have created a short QTP tutorial for
moving your mouse cursor on any object in your application.

I used Google webpage to create this small tutorial on HP Quicktest Professional. This script will hover
over the mouse cursor inside the search box.(It will not click inside the search box, it will simply bring
the mouse over the search box)

The QTP Script goes here:

x=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:=q").
GetROProperty("abs_x")
y=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:=q").
GetROProperty("abs_y")
Set obj=CreateObject("Mercury.DeviceReplay")
obj.MouseMove x,y

Please make sure to resize your QTP window and your application before running the above HP QTP
script as shown below to see the effect:
As you have noticed, your
mouse cursor has been shifted to the extreme left corner of the search box. To place it somewhere in
the middle, modify the fourth line in the above script to:

obj.MouseMove x+10,y+10

The output after modifying the QTP script would be as shown below:

Explanation of the above


QTP code:

1. "abs_x" and "abs_y" are the object's absolute x and y coordinate relative to the screen. Hence we
are finding the extreme top-left coordinate of the search box using the first two lines.

2. Mercury.DeviceReplay object is an undocumented feature in QTP which is usually used to simulate


either keyboard inputs or mouse clicks or mouse movements. Also, to use "Mercury.DeviceReplay"
object in HP Quicktest Professional, you need to make sure that your Application is currently the active
window. So for the above code, we created an object reference for DeviceReplay object in QTP( here
in our case, I used obj) and using that object reference, we used the MouseMove method to shift the
mouse cursor to the desired location.

Just like we used MouseMove to shift my mouse cursor over the search box, we can also simulate
clicking on an object using MouseClick.

Syntax of MouseClick Method


object.MouseClick x,y, Button

object: It should always be Mercury.DeviceReplay object


x: The object's absolute x coordinate relative to the screen
y: The object's absolute y coordinate relative to the screen
Button: It can have 3 values
1. For Left Mouse Click use 0
2. For Middle Mouse Click use 1
3. For Right Mouse Click use 2

Hence, if we want to do a left mouse click inside Google search box, our QTP script would be:

x=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:=q").
GetROProperty("abs_x")
y=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:=q").
GetROProperty("abs_y")

Set obj=CreateObject("Mercury.DeviceReplay")

obj.MouseClick x+10,y+10,0

And, if you want to do a right mouse click, replace the last line of above code with the following:

obj.MouseClick x+10,y+10,2

Note: The above code will run successfully if you will resize your QTP window while the script is
running so that the search box is not hidden by the QTP window while the script is running otherwise it
may not work as desired.

Do you have any questions related to this QTP Article? Feel free to ask me. Please post your queries
in the comments section.

Click here to read how to check if a DataTable Parameter exists or not

Click here to read how to check if a DataTable Sheet exists or not

Click here to read tutorial on Regular Expressions

Posted by QTP Expert at 11:21 PM 2 comments

Sunday, October 11, 2009

QTP Script: Checking if Datatable Parameter exists


In my previous article of Checking if a Data Table Sheet exists, I have shown a QTP script which
checks if a sheet exists or not in your Datatable. Today, I am going to show you how to check if a
parameter exists or not in your DataTable.

The algorithm goes here:


Step I : Use the On Error Resume Next statement to disable any error popups.
Step II : Use the DataTable's GetSheet method to return the specified sheet. Then add the
GetParameter method to seach for the parameter. The following syntax should be used:
DataTable.GetSheet("Your Sheet").GetParameter(" Your Parameter")
Step III : Check for an error number using Err.Number. If case of no error, Err.Number should return 0.

With the above algorithm, our QTP Script goes here:

'Disable Error Reporting in QTP


On Error Resume Next

'Check for the existence of "Global" sheet inside QTP. Then search for "HPQTP" parameter inside
"Global" sheet
DataTable.GetSheet("Global").GetParameter("HPQTP")

If Err.Number<>0 Then
Msgbox "The specified parameter does not exists"
Else
Msgbox "The specified parameter exists"
End If

'Enable Error Reporting in QTP


On Error Goto 0

Click here to see the script for Checking if Data table sheet exists

Posted by QTP Expert at 3:56 PM 0 comments

QTP Script: Checking if Data table sheet exists


Is there any way to check if a DataTable sheet exists? Yes, offcourse. Open the DataTable and see
manually. Now, is there any way to check through code if a DataTable sheet exists? Hmmmm.. Yes it
is.

I have created a small algorithm to check if a HP QTP DataTable sheet exists or not. The algorithm
goes here:

Step I : Use the On Error Resume Next statement to disable any error popups.
Step II : Use the DataTable's GetSheet method to return the specified sheet. The following syntax
should be used:
DataTable.GetSheet("Your Sheet")
Step III : Check for an error number using Err.Number. If case of no error, Err.Number should return 0.

With the above algorithm, our QTP Script goes here:

'Disable Error Reporting in QTP


On Error Resume Next

'Check for the existence of a sheet inside QTP


DataTable.GetSheet("Global")

If Err.Number<>0 Then
Msgbox "The specified Sheet does not exists"
Else
Msgbox "The specified Sheet exists"
End If

'Enable Error Reporting in QTP


On Error Goto 0

Click here to see the script for Checking if Data table Parameter exists

Sunday, October 11, 2009

QTP Script: Checking if Datatable Parameter exists


In my previous article of Checking if a Data Table Sheet exists, I have shown a QTP script which
checks if a sheet exists or not in your Datatable. Today, I am going to show you how to check if a
parameter exists or not in your DataTable.

The algorithm goes here:

Step I : Use the On Error Resume Next statement to disable any error popups.
Step II : Use the DataTable's GetSheet method to return the specified sheet. Then add the
GetParameter method to seach for the parameter. The following syntax should be used:
DataTable.GetSheet("Your Sheet").GetParameter(" Your Parameter")
Step III : Check for an error number using Err.Number. If case of no error, Err.Number should return 0.

With the above algorithm, our QTP Script goes here:

'Disable Error Reporting in QTP


On Error Resume Next

'Check for the existence of "Global" sheet inside QTP. Then search for "HPQTP" parameter inside
"Global" sheet
DataTable.GetSheet("Global").GetParameter("HPQTP")

If Err.Number<>0 Then
Msgbox "The specified parameter does not exists"
Else
Msgbox "The specified parameter exists"
End If

'Enable Error Reporting in QTP


On Error Goto 0
Click here to see the script for Checking if Data table sheet exists

Posted by QTP Expert at 3:56 PM

0 comments:

Sunday, October 11, 2009

QTP Script: Checking if Data table sheet exists


Is there any way to check if a DataTable sheet exists? Yes, offcourse. Open the DataTable and see
manually. Now, is there any way to check through code if a DataTable sheet exists? Hmmmm.. Yes it
is.

I have created a small algorithm to check if a HP QTP DataTable sheet exists or not. The algorithm
goes here:

Step I : Use the On Error Resume Next statement to disable any error popups.
Step II : Use the DataTable's GetSheet method to return the specified sheet. The following syntax
should be used:
DataTable.GetSheet("Your Sheet")
Step III : Check for an error number using Err.Number. If case of no error, Err.Number should return 0.

With the above algorithm, our QTP Script goes here:

'Disable Error Reporting in QTP


On Error Resume Next

'Check for the existence of a sheet inside QTP


DataTable.GetSheet("Global")

If Err.Number<>0 Then
Msgbox "The specified Sheet does not exists"
Else
Msgbox "The specified Sheet exists"
End If

'Enable Error Reporting in QTP


On Error Goto 0

Click here to see the script for Checking if Data table Parameter exists

Posted by QTP Expert at 2:29 PM

0 comments:

Das könnte Ihnen auch gefallen