Showing posts with label QTP Script. Show all posts
Showing posts with label QTP Script. Show all posts

Saturday, September 27, 2008

QTP Checkpoint Return Value Example

QTP 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)

Now run the test and see the msgbox appearing with the return value.

QTP Bitmap Checkpoint Example

QTP 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

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

Go to Insert (menu)->Checkpoint->Bitmap Checkpoint

Click on the "Fly To" combo box.
"Object Selection- Bitmap Checkpoint Properties" window opens up. I will have "WinComboBox:Fly To" highlighted. Click ok
It will open "Bitmap Checkpoint Properties" window.

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

QTP Standart Checkpoints

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
Open a blank test.
Make sure that Flight application is open.(Now only QTP with blank test and Flight application should be open).
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.
Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).The mouse pointer will become hand and QTP will be minimized.
Click on the "Flights..." button which is on the Right Hand Side of the "Fly To" combo box in the Flight application.
It will open "Object Selection - Checkpoint Properties" window (with WinButton:FLIGHT highlighted). Click ok.
It will open checkpoint properties window. (only one property will be checked in it i.e. 'enabled' with a value of False.)
Click ok. Click on Stop in order to stop the Recording.
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.

QTP Data Table Access with QTP 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.