Sunday, November 7, 2010

Custom Checkpoints

QTP Custom Checkpoints

A Checkpoint is a verification point that compares the current value for specified properties with the expected value for those properties. (QTP Help)

Custom Checkpoints let you do more and help you to be more flexible with your coding.

In simple terms you create Custom Checkpoints with the use of Conditional Statements or Looping statements, Exist, GetROProperty, Reporter. ReportEvent etc.

ReporterEvent Method of Reporter object is simply used to send any information to the test results. I will not use that here. I am simply using VBScript’s Msgbox function instead to keep it simple. Below is just very quick & simple explanation of Reporter.ReportEvent. You can also view Reporter Object here.

Reporter.ReportEvent

Syntax of Reporter.ReportEvent:

Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]



Example 1 of Reporter.ReportEvent:

[Just see the Arguments passed to the Reporter.ReportEvent and how they appear in the Test Results]




Example 2 of Reporter.ReportEvent:

[Just see the Arguments passed to the Reporter.ReportEvent and how they appear in the Test Results]



Example 1 of Custom Checkpoints
(Uses IF…End IF statement and GetROProperty)



This is just a fictitious example in order to make you understand (depending on different situations we can do different things).

Open www.google.co.in
Write the below code in a new test in QTP.
This code checks that if the value in the Google Search text box is "QTP" then it clicks on the "About Google" link at the bottom of the page, else it clicks on the "I'm Feeling Lucky" button.



Example – 2 of Custom Checkpoints
(Uses IF…End IF statement and GetROProperty)


On the Search Settings page, if Interface Language List Box has a value of "Finnish" and Search Language "Afrikaans" is Checked, only then click on Save Preferences button.



Example 3 of Custom Checkpoints
(Uses IF…End IF statement and Exist)

Below you can see that google.com has "Business Solutions" link on the right of Advertising Programs. Google.co.in does not have that.


This is just another simple example which shows that if a certain control (e.g. link in this example) exists on a web page then do certain actions else do some other actions.


Example 4 of Custom Checkpoints
(Database Checkpoint using IF..End IF)

Below example is using a simple check that if there is certain no. of records in a table, then only show the value of first column for each record. You can use AND to join two conditions and further go on, the possibilities are endless.




Example 5 of Custom Checkpoints

Firstly a QTP XML Checkpoint is used and then same example with Custom Checkpoint.

Create XML File as shown. Write the text in a Notepad and save it as .XML file.


Go to Insert-> Checkpoint-> XML Checkpoint(From Resource).
"XML Source Selection - Checkpoint Properties" dialog opens.
Select "Create checkpoint from XML file" radio button.
Select the XML file we created earlier. Click OK.
XML Checkpoint Properties dialog box opens.


Type "grade" for Attribute and "95" for Value and click OK.


Checkpoint is inserted in a new test in QTP.


Run this test. Check the results.


Change the value of grade in the xml file and run the test again.


Check the results again.


Click on View XML Checkpoint Results button and check the expected and actual value of grade.


Custom Checkpoint



The above code will show Pass if grade is 95 and Fail otherwise.

This is just a simple example to show how you can expand your thinking and free yourself from limited use of QTP checkpoints and may not be the best way out there.


You can also read the above post in PPT Format.