15 QTP Interview Questions and Answers
Prepare for your next interview with our comprehensive guide on QTP, featuring common and advanced questions to enhance your automated testing skills.
Prepare for your next interview with our comprehensive guide on QTP, featuring common and advanced questions to enhance your automated testing skills.
QuickTest Professional (QTP), now known as Micro Focus UFT (Unified Functional Testing), is a widely-used tool for automated functional and regression testing. It supports keyword and scripting interfaces and features a robust set of functionalities for testing web, desktop, and mobile applications. QTP’s integration with various test management tools and its ability to support multiple environments make it a valuable skill for software testers.
This article provides a curated selection of interview questions designed to help you demonstrate your proficiency with QTP. By reviewing these questions and their detailed answers, you can better prepare for technical interviews and showcase your expertise in automated testing.
QTP, now known as Micro Focus UFT (Unified Functional Testing), is an automated testing tool for functional and regression testing. It uses VBScript to specify test procedures and manipulate application objects.
QTP is primarily used for:
An Object Repository in QTP is a collection of object descriptions used to identify and interact with application objects. There are two types:
Objects are identified based on properties like name and type. The repository stores these properties, allowing QTP to recognize objects during test execution.
Dynamic objects in QTP have frequently changing properties, making them hard to identify with standard repositories. Descriptive programming allows you to specify property-value pairs directly in the script to identify these objects.
Example:
' Using descriptive programming to handle a dynamic button Set btnDynamic = Browser("BrowserName").Page("PageName").WebButton("html tag:=INPUT", "type:=submit", "name:=btnSubmit") ' Perform an action on the dynamic button btnDynamic.Click
This approach is useful when object properties change frequently.
QTP offers three recording modes:
Parameterization in QTP allows test scripts to accept different data inputs, enhancing flexibility and reusability. Methods include:
Checkpoints in QTP verify that the application functions as expected by comparing actual outcomes with expected ones. Types include:
To implement a checkpoint, use the Checkpoint feature in QTP.
In QTP, exceptions can be managed using Recovery Scenarios and VBScript’s error handling.
Recovery Scenarios define instructions to recover from unexpected events during test execution. They consist of Trigger Event, Recovery Steps, Post-Recovery Test Run, and Recovery Scenario Name.
VBScript’s error handling uses the On Error Resume Next
statement to continue executing the next line of code when an error occurs. The Err
object checks for errors and handles them.
Example:
' Enable error handling On Error Resume Next ' Code that may cause an error Set obj = CreateObject("NonExistent.Object") ' Check for errors If Err.Number <> 0 Then ' Handle the error Reporter.ReportEvent micFail, "Error", "An error occurred: " & Err.Description ' Clear the error Err.Clear End If ' Disable error handling On Error GoTo 0
Descriptive Programming in QTP allows specifying object properties and values directly in the script, bypassing the object repository. This is useful for dynamic objects.
Example:
' Using Descriptive Programming to click a button Set objButton = Browser("title:=Google").Page("title:=Google").WebButton("name:=Google Search") objButton.Click
Regular expressions in QTP handle dynamic objects and text strings by defining a search pattern that can match multiple strings.
Example:
' Using regular expressions in QTP to identify a dynamic object Set objDesc = Description.Create objDesc("html tag").Value = "INPUT" objDesc("name").Value = "user.*" ' Regular expression to match any name starting with "user" Set obj = Browser("Browser").Page("Page").ChildObjects(objDesc) If obj.Count > 0 Then obj(0).Set "example" End If
The regular expression “user.*” matches any object whose name starts with “user.”
Smart Identification in QTP identifies objects when recorded properties do not match during playback. It uses:
If QTP cannot identify the object using these properties, Smart Identification uses predefined properties.
Environment variables in QTP store values accessible throughout test scripts. They can be built-in or user-defined. Built-in variables provide information about the test environment, while user-defined variables store custom values.
Example:
' Accessing a built-in environment variable Dim osName osName = Environment.Value("OS") ' Creating and setting a user-defined environment variable Environment.Value("URL") = "http://example.com" ' Accessing a user-defined environment variable Dim url url = Environment.Value("URL") ' Using the environment variable in a test step Browser("Browser").Navigate url
Keyword-Driven Testing uses keywords to represent actions on the application under test. Components include:
The driver script interprets keywords and interacts with the application.
QTP and Selenium are both automated testing tools with key differences:
A shared object repository in QTP is a centralized storage for objects used across multiple test scripts. To create one:
Associate the shared repository with test scripts via the Resources menu.
To create a custom function in QTP and call it within a test:
1. Define the function in a function library.
2. Associate the library with your test.
3. Call the function in your test.
Example:
' Define the custom function in a function library Function AddNumbers(a, b) AddNumbers = a + b End Function ' Save the above code in a file named "FunctionLibrary.vbs" ' In your QTP test, associate the function library ' Go to File -> Settings -> Resources -> Add the "FunctionLibrary.vbs" file ' Call the custom function within your test Dim result result = AddNumbers(5, 10) MsgBox "The result is: " & result