QTP Interview Questions and Answers – Part 4

Share This Post -

How can we define a time interval for QTP to perform a checkpoint successfully?
You can specify the time interval during which QTP attempts to perform the checkpoint successfully by modifying the selections in the bottom part of the Text/Text Area Checkpoint Properties dialog box. You can also specify when to perform the checkpoint.

• Checkpoint timeout. Specifies the time interval (in seconds) during which QTP attempts to perform the checkpoint successfully. QTP continues to perform the checkpoint until it passes or until the timeout occurs. If the checkpoint does not pass before the timeout occurs, the checkpoint fails.

For example, suppose it takes some time for an object to achieve an expected state. Increasing the checkpoint timeout value in this case can help ensure that the object has sufficient time to achieve that state, enabling the checkpoint to pass (if the data matches) before the maximum timeout is reached.
If you specify a checkpoint timeout other than 0, and the checkpoint fails, the Test Results window displays information on the checkpoint timeout.

• Insert statement. Specifies when to perform the checkpoint. Choose Before current step if you want to check the value of the text before the highlighted step is performed. Choose After current step if you want to check the value of the text after the highlighted step is performed.

Note: The Insert statement option is not available when adding a new text checkpoint or a text area checkpoint during recording, or when modifying an existing checkpoint. It is available only when adding a new text checkpoint to an existing test while editing.

How can we Disable Smart Identification During the Run Session in QTP?
Selecting the Enable Smart Identification check box for a particular test object class instructs QTP to learn the property values of all properties specified as the object's base and/or optional filter properties in the Smart Identification Properties dialog box.
By default, some test objects already have Smart Identification configurations and others do not. Those with default configurations also have the Enable Smart Identification check box selected by default.

You should enable the Smart Identification mechanism only for test object classes that have defined Smart Identification configuration.

However, even if you define a Smart Identification configuration for a test object class, you may not always want to learn the Smart Identification property values. If you do not want to learn the Smart Identification properties, (To Disable Smart Identification in QTP) clear the Enable Smart Identification check box.

Note: Even if you choose to learn Smart Identification properties for an object, you can disable use of the Smart Identification mechanism for a specific object in the Object Properties or Object Repository dialog box.
However, if you do not learn Smart Identification properties, you cannot enable the Smart Identification mechanism for an object later.

How can we do part running of the QTP Test script?
The Run from Step option in the Test menu is used to run the test from a selected step to the end of the current action, if running from the Expert View, or to the end of the test , if running from the Keyword View. Thus it enables us to check a specific part of the application or to confirm that a certain part of the test runs correctly.

How can I check by QTP that a child window exists (or does not exist)?
Sometimes a link in one window creates another window.
You can use the Exist property to check whether or not a window exists. For example:
You can also use the ChildObjects method to retrieve all child objects (or the subset of child objects that match a certain description) on the Desktop or within any other parent object.
How can we do the nesting of If...Then...Else statement in QTP?
If condition Then
[ElseIf condition-n Then
[elseifstatements] . . .
End If

How can we ensure that a text string appears in a specified area in QTP?
In the Text/Text Area Checkpoint Properties dialog box, you can specify the text to be checked as well as which text is displayed before and after the checked text. These configuration options are particularly helpful when the text string you want to check appears several times or when it could change in a predictable way during run sessions.

For example, suppose you want to check the third occurrence of a particular text string in a page. To check for this string, you can specify which text precedes and/or follows it and to which occurrence of the specified text string you are referring.

7. How can we identify a checkpoint in QTP?
QTP enables you to add checks to your test. A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. This enables you to identify whether your Web site or application is functioning correctly.

When you add a checkpoint, QTP 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. You can choose to specify a different name for the checkpoint or accept the default name.

When you run the test, QTP compares the expected results of the checkpoint to the current results. If the results do not match, the checkpoint fails. You can view the results of the checkpoint in the Test Results window.

Tip: You can also use the CheckProperty method and the CheckItemProperty method to check specific property or item property values.

Note: If you want to retrieve the return value of a checkpoint (a boolean value that indicates whether the checkpoint passed or failed), you must add parentheses around the checkpoint argument in the statement in the Expert View. For example:
a = Browser("MyBrowser").Page("MyPage").Check (CheckPoint("MyProperty"))

How can we incorporate decision-making into the QTP tests?
Using conditional statements, you can incorporate decision making into your tests. Using loop statements, you can run a group of steps repeatedly, either while or until a condition is true. You can also use loop statements to repeat a group of steps a specific number of times.

After you insert a conditional or loop statement in the Keyword View, you can insert or record steps after the statement to include them in the conditional or loop block.

How can we increase the Readability of our QTP Tests scripts?
To increase readability, use With Statement.
You can instruct QTP to automatically generate With statements for the steps you record. When you select this option, statements are displayed in their normal format while recording. When you stop recording, the statements in all actions recorded during the current recording session are automatically converted to the With format.

To generate With statements automatically when you record:
1. Choose Tools > Options or click the Options toolbar button. The Options dialog box opens.
2. In the General tab, select Automatically generate "With" statements after recording.
3. Enter the minimum number of consecutive, identical objects for which you want to apply the With statement in the Generate "With" statements for __ or more objects box.
The default is 2.
Note: This setting is used when you use the Apply "With" to Script option as well as for the Automatically generate "With" statements after recording option.
For example, if you only want to generate a With statement when you have three or more consecutive statements based on the same object, enter 3.
4. Begin recording your test. While recording, statements are recorded normally. When you stop recording, the statements in all actions recorded during the current recording session are automatically converted to the With format.
The With statement has the following syntax.
With object
End With
For example, you could replace this script:
Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Los Angeles"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "19097 LON "
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
with the following:
With Window("Flight Reservation")
.WinComboBox("Fly From:").Select "London"
.WinComboBox("Fly To:").Select "Los Angeles"
With .Dialog("Flights Table")
.WinList("From").Select "19097 LON "
End With 'Dialog("Flights Table")
End With 'Window("Flight Reservation")

Note: Using With statements in your test has no effect on the run session itself, only on the way your test appears in the Expert View. Generating With statements for your test does not affect the Keyword View in any way.

How does QTP record on dynamically generated URLs and Web pages?
QTP actually clicks links as they are displayed on the page. Therefore, QTP records how to find a particular object, such as a link on the page, rather than the object itself. For example, if the link to a dynamically generated URL is an image, then QTP records the "IMG" HTML tag, and the name of the image. This enables QTP to find this image in the future and click on it.

How can we insert a checkpoint or output value statement in Expert View of QTP Manually?
We cannot insert standard checkpoints and other predefined checkpoints or output value statement in Expert View of QTP Manually.
But we can insert descriptive checkpoints (Like If… Else) in the expert view of QTP while editing/updating the test scripts.

How can we Insert statement option when adding a checkpoint during the recording?
How can we Integrate QTP with Quality Center?
At its most basic level, integrating QTP with Quality Center enables you to store and access QTP tests and function libraries in a Quality Center project, when QTP is connected to Quality Center.

In addition, your tests and function libraries can use the QCUtil object to access and use the full functionality of the Quality Center OTA (Open Test Architecture)—formerly known as TestDirector OTA or TDOTA. This enables you to automate integration operations during a run session, such as reporting a defect directly to a Quality Center database.
You can also use the TDOTA object in your QTP automation scripts to access the Quality Center OTA.

How can we locate Test Objects in an Object Repository in QTP?
You can select an object in the application or Web site you are testing and highlight the test object in the object repository.

For example, to locate a Find a Flight image in a Web page, you can select it in your Web page using the pointing hand mechanism. After you select the Find a Flight image object from the selection dialog box and click OK, the parent hierarchy in the object repository tree expands and the Find a Flight image test object is highlighted.

To locate an object in the object repository:
1. Make sure your application or Web site is open to the correct window or page.
2. Click the Locate in Repository button or choose View > Locate in Repository. QTP is hidden, and the pointer changes into a pointing hand.
3. Use the pointing hand to click on the required object in your application or Web site.
Tip: You can hold the left CTRL key to change the window focus or perform operations such as right-clicking or moving the pointer over an object to display a context menu. If the window containing the object you want to click is partially hidden by another window, you can also hold the pointing hand over the partially hidden window for a few seconds until the window comes into the foreground and you can point and click on the object you want. Additionally, if the window containing the object you want to select is minimized, you can display it by holding the left CTRL key, right-clicking the application in the Windows task bar, and choosing Restore from the context menu.
If the location you clicked is associated with more than one object, the Select an Object dialog box opens.
4. Select the object you want to locate in the object repository and click OK. The selected object is highlighted in the object repository.
Tip: If the relevant object repository is not open or the object cannot be found, the object is not highlighted. In the Object Repository Manager, if more than one shared object repository is open, and QTP cannot locate the selected object in the active object repository, you can choose whether to look for the object in all of the currently open object repositories.

How does QTP handle cookies?
Server side connections, such as CGI scripts, can use cookies both to store and retrieve information on the client side of the connection.
QTP stores cookies in the memory for each user, and the browser handles them as it normally would.

How can we parameterize a step in QTP?
Parameterize the method argument of the fromPort step:
In the Keyword View, click in the Value cell of the step and then click the parameterization icon. In the Value Configuration Options dialog box, select the Parameter radio button. In the Name box, rename p_item to Location.
Click OK. The Location column is added to the Data Table.

How can we perform Import & Export Operations among various Object Repositories in QTP?
You can export all of the objects contained in an action's local object repository to a new shared object repository in the file system or to a Quality Center project (if QTP is connected to Quality Center). This enables you to make the local objects accessible to other actions. You export local objects to a new shared object repository using the Object Repository window.

To export local objects to a new shared object repository:
1. Open the test that has the local objects you want to export.
2. Make sure that the Object Repository window is open.
3. In the Object Repository window, in the Action box, choose the action whose local objects you want to export.
4. Choose File > Export Local Objects. The Export Object Repository dialog box opens.
Note: If you are connected to Quality Center, the dialog box that opens is different from the standard file system dialog box. You can switch between the two dialog box versions by clicking the File System and Quality Center buttons in the Export Object Repository dialog box.
5. Select the location in which to save the file, specify the file or attachment name, and click Save or OK (depending on whether you are saving it to the file system or a Quality Center project).
The object repository is exported to the specified shared object repository (a file with a .tsr extension). You can now use the new shared object repository like any other shared object repository.
Tip: After you export the local objects, you can use the Object Repository Merge Tool to merge the shared object repository containing the exported objects with another shared object repository.

How can we perform Merge Operations among various Object Repositories in QTP?
QTP Professional provides the ability to merge existing assets from two object repositories into a single shared object repository using the Object Repository Merge Tool. This tool enables you to merge two shared object repositories (called the primary object repository and the secondary object repository), into a new third object repository, called the target object repository. Objects in the primary and secondary object repositories are automatically compared and then added to the target object repository according to preconfigurable rules that define how conflicts between objects are resolved.

After the merge process, the Object Repository Merge Tool provides a graphic presentation of the original objects in the primary and secondary object repositories, which remain unchanged, as well as the objects in the merged target object repository. Objects that had conflicts are highlighted. The conflict of each object that you select in the target object repository is described in detail. The Object Repository Merge Tool provides specific options that enable you to keep the suggested resolution for each conflict, or modify each conflict resolution individually, according to your requirements.

The Object Repository Merge Tool also enables you to merge objects from the local object repository of one or more actions into a shared object repository. For example, if QTP learned objects locally in a specific action in your test, you may want to add the objects to the shared object repository, so that they are available to all actions in different tests that use that object repository.

You open the Object Repository Merge Tool by choosing Tools > Object Repository Merge Tool in the Object Repository Manager.
How can we retrieve all objects located inside a Parent Object with QTP?
You can use the ChildObjects method to retrieve all objects located inside a specified parent object, or only those child objects that fit a certain programmatic description. To retrieve this subset of child objects, you first create a description object and add the set of properties and values that you want your child object collection to match using the Description object.
Note: You must use the Description object to create the programmatic description for the ChildObjects description argument. You cannot enter the programmatic description directly into the argument using the property:=value syntax.
Once you have "built" a description in your description object, use the following syntax to retrieve child objects that match the description:

Set MySubSet=TestObject.ChildObjects(MyDescription)
For example, the statements below instruct QTP to select all of the check boxes on the Itinerary Web page:
Set MyDescription = Description.Create()
MyDescription("html tag").Value = "INPUT"
MyDescription("type").Value = "checkbox"
Set Checkboxes = Browser("Itinerary").Page("Itinerary").ChildObjects(MyDescription)
NoOfChildObjs = Checkboxes.Count
For Counter=0 to NoOfChildObjs-1
Checkboxes(Counter).Set "ON"
In the Test Results, square brackets around a test object name indicate that the test object was created dynamically during the run session using the ChildObjects method or a programmatic description.

Where can I find a Web page's cookie with QTP?
The cookie used by the browser can be accessed through the browser's Document Object Model (DOM). In the following example the cookie collection is returned the from the browser.
Browser("Flight reservations").Page("Flight reservations").Object.Cookie