Sunday, March 25, 2012

Checkpoints in QTP 11 (QuickTest Professional)

  A checkpoint enables you to identify whether the Web site or application under test is functioning correctly or not by comparing a current value for a particular property with the expected value for that property.

After we add a checkpoint, QuickTest adds a checkpoint to the current row in the Keyword View and adds a Check CheckPoint statement in the Expert View.
By default, the checkpoint name receives the name of the test object on which the checkpoint is being performed. We can change the name of the checkpoint if
needed.

Types of Checkpoints:

  1. Standard checkpoint
  2. Image checkpoints
  3. Bitmap Checkpoint
  4. Table checkpoints
  5. Accessibility Checkpoint
  6. Text Checkpoint
  7. Page Checkpoint
  8. Database Checkpoint
  9. XML checkpoints

Standard checkpoints allow checking the object property values in the Web site or application under test. Standard checkpoints evaluate (compare) the expected values of object properties captured during recording to the object's current values during a run session. For
example we can check that a radio button is activated after it is selected. Standard checkpoints are supported for all add-in environments.
Standard checkpoints can be used to perform checks onImages,Tables,Web page properties, andOther objects within your application or Web site.
Standard checkpoints can be created for all supported testing environments (as long as the appropriate add-in(s) are loaded).

Image checkpoints allow you to check the properties of an image in the application or Web page. For example, you can check that a selected image's source file is correct or not. An image checkpoint can also be created by inserting a standard checkpoint on an image object. Image checkpoints are supported for the Web add-in environment

Bitmap Checkpoint we can check an area of a Web page or application as a bitmap. While creating a test, we have to specify the area to check by selecting an object. An entire object or any area within an object can be checked. Bitmap checkpoints are supported for all add-in environments

By adding table checkpoints to the test, we can check the content of tables displayed in the application. For example, we can check that a specified value is displayed in a certain cell. Certain environments also support checking the properties of the table object. For example, a check that a table has the expected number of rows and columns. A table checkpoint can also be created by inserting a standard checkpoint on a table object.

Accessibility Checkpoint recognizes areas of your Web site that may not conform to the World Wide Web Consortium (W3C) Web Content Accessibility Guidelines. For example, check if the images on a Web page include ALT properties, required by the W3C Web Content Accessibility Guidelines. Accessibility checkpoints are supported for the Web add-in environment

QuickTest can check that a text string is displayed in the appropriate place in an application or on a Web page with Text Checkpoint. Text checkpoints are supported for the Web add-in environment, plus some Web-based add-in environments

Page Checkpoint checks the features of a Web page. For example, you can check how long a Web page takes to load or whether a Web page contains broken links. A page checkpoint can also be created by inserting a standard checkpoint on page object. Page checkpoints are supported for the Web add-in environment

The contents of a database accessed by your application can be checked by Database Checkpoint. Database checkpoints are supported for all add-in environments

By adding XML checkpoints to your test, you can check the contents of individual XML data files or documents that are part of your Web application. The XML Checkpoint option is supported for all add-in environments.


QuickTest Professional offers the following types of checkpoints:
Checkpoint Type Description Example of Use
Standard Checkpoint Checks values of an object's properties. Check that a radio button is selected.
Image Checkpoint Checks the property values of an image. Check that the image source file is correct.
Table Checkpoint Checks information in a table. Check that the value in a table cell is correct.
Page Checkpoint Checks the characteristics of a Web page. Check how long a Web page takes to load or if a Web page contains broken links.
Text Checkpoint Checks that a text string is displayed in the appropriate place in a Web page or application. Check whether the expected text string is displayed in the expected location in a test object.
Text Area Checkpoint Checks that a text string is displayed within a defined area in a Windows-based application. Check that an area of a dialog box includes text that was entered in another part of the application.
Bitmap Checkpoint Checks an area of a Web page or application after capturing it as a bitmap. Check that a Web page (or any portion of it) is displayed as expected.
Database Checkpoint Checks the contents of databases accessed by an application or Web site. Check that the value in a database query is correct.
Accessibility Checkpoint Identifies areas of a Web site to check for Section 508 compliancy. Check if the images on a Web page include ALT properties, required by the W3C Web Content Accessibility Guidelines.
XML Checkpoint Checks the data content of XML documents. Check the content of an element to make sure that its tags, attributes, and values have not changed. Note: XML file checkpoints are used to check a specified XML file; XML application checkpoints are used to check an XML document within a Web page.

Wednesday, March 21, 2012

How to Record a Test in QTP?

Start QuickTest  and open a new test.
If QuickTest is not currently in your desktop, choose Start > Programs > QuickTest Professional > QuickTest Professional.

In the Add-in Manager, confirm that the Web Add-in is selected, and clear all other add-ins. Click OK to close the Add-in Manager and open QuickTest.


Note: While QuickTest loads your selected add-ins, the QuickTest splash screen is displayed. This may take a few seconds.

If the Welcome window opens, click Blank Test.

Otherwise, choose File > New > Test, or click the New button  down arrow and choose Test.

Note: If a test is already open, clicking the New toolbar button opens a new test.

A blank test opens.

If QuickTest is already open, check which add-ins are loaded by selecting Help > About QuickTest Professional. If the Web Add-in is not loaded, you must exit and restart QuickTest. When the Add-in Manager opens, select the Web Add-in, and clear all other add-ins.
Note: If the Add-in Manager does not open when starting QuickTest, choose Tools > Options. In the General tab, select Display Add-in Manager on startup. When you exit and restart QuickTest, the Add-in Manager opens.

Start recording on the Mercury Tours Web site.

Choose Automation > Record or click the Record button . The Record and Run Settings dialog box opens.

Select "Record and run test on any open browser"

Shortcut key for Record is ""

Saturday, December 10, 2011

For...Each Statement in HP QTP

For...Each Statement
A For...Each loop instructs QuickTest to perform one or more statements for each element in an array or an object collection. It has the following syntax:

For Each item In array
    statement
Next

Item  Description
item  A variable representing the element in the array. 
array  The name of the array. 

statement  A statement, or series of statements, to be performed during the loop. 
The following example uses a For...Each loop to display each of the values in an array:

MyArray = Array("one","two","three","four","five")
For Each element In MyArray
    msgbox element
Next


Note: During a run session, if a For Each statement iterates on the Parameter Definitions collection, the run may fail if the collection was retrieved directly before using the For Each statement. To prevent this, use other VBScript loop statements, such as For or While.

Do...Loop Statement in VB Script

Do...Loop Statement
The Do...Loop statement instructs QuickTest to perform a statement or series of statements while a condition is true or until a condition becomes true. It has the following syntax:

Do [{while} {until} condition]
    statement
Loop


Item           Description  
Condition     A condition to be fulfilled.  
Statement     A statement or series of statements to be performed during the loop. 

In the following example, QuickTest calculates the factorial value of the number of passengers using the Do...Loop:

passengers = Browser("Mercury Tours").Page("Find Flights").WebEdit("numPassengers").GetROProperty("value")
total = 1
i = 1
Do while i <= passengers
     total = total * i
     i = i + 1
Loop
MsgBox "!" & passengers & "=" & total  

Variables in VBScript

Variables in VBScript

You can specify variables to store test objects or simple values in your test or function library. When using a variable for a test object, you can use the variable instead of the entire object hierarchy in other statements. Using variables in this way makes your statements easier to read and to maintain.
To specify a variable to store an object, use the Set statement, with the following syntax:
Set ObjectVar = ObjectHierarchy
In the example below, the Set statement specifies the variable UserEditBox to store the full Browser.Page.WebEdit object hierarchy for the username edit box. The Set method then enters the value John into the username edit box, using the UserEditBox variable:
Set UserEditBox = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username")
UserEditBox.Set "John"
Note: Do not use the Set statement to specify a variable containing a simple value (such as a string or a number). The example below shows how to define a variable for a simple value:

MyVar = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").GetTOProperty("type")
You can also use the Dim statement to declare variables of other types, including strings, integers, and arrays. This statement is not mandatory, but you can use it to improve the structure of your test or function library. In the following example, the Dim statement is used to declare the passengers variable, which can then be used in different statements within the current action or function library:
Dim passengers
passengers = Browser("Mercury Tours").Page("Find Flights").WebEdit("numpassengers").GetROProperty("value")

How to Opening and Closing Applications Programmatically in QTP

Opening and Closing Applications Programmatically
In addition to using the Record and Run Settings dialog box to instruct QuickTest to open a new application when a test run begins, or manually opening the application you want to test, you can insert statements into your test that open and close the applications you want to test.

You can run any application from a specified location using a SystemUtil.Run statement. This is especially useful if your test includes more than one application, and you selected the Record and run test on any application check box in the Record and Run Settings dialog box. You can specify an application and pass any supported parameters, or you can specify a file name and the associated application starts with the specified file open.

You can close most applications using the Close method. You can also use SystemUtil statements to close applications.

For example, you could use the following statements to open a file named type.txt in the default text application (Notepad), type happy days, save the file using shortcut keys, and then close the application:

SystemUtil.Run "C:\type.txt", "","",""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close


Note:

When you specify an application to open using the Record and Run Settings dialog box, QuickTest does not add a SystemUtil.Run statement to your test.
The InvokeApplication method can open only executable files and is used primarily for backward compatibility.

Expert View and Keyword View - A Comparison

If you prefer to work with VBScript statements, you can choose to work with your tests in the Expert View, as an alternative to using the Keyword View. You can move between the two views as you wish, by selecting the Expert View or Keyword View tab at the bottom of the Test pane in the QuickTest window.

The Expert View displays the same steps and objects as the Keyword View, but in a different format:

In the Keyword View, QuickTest displays information about each step and shows the object hierarchy in an icon-based table. For more information, see Keyword View.
In the Expert View, QuickTest displays each step as a VBScript line or statement. In object-based steps, the VBScript statement defines the object hierarchy.

The following diagram shows how the same object hierarchy is displayed in the Expert View and in the Keyword View: