Wednesday, June 3, 2009

QTP Test Automation Framework

TABLE OF CONTENTS

1 KEYWORD-DRIVEN SCRIPTING .......................................

2 CREATING NEW TEST .............................................

2.1 Test Creation in QTP ....................................................

2.2 Test Generation from QC ..................................................

3 TEST SETTINGS FOR KEYWORD-DRIVEN SCRIPTING .........................

3.1 Run Settings ............................................................

3.2 Resources Settings .......................................................

3.3 Environment Tab Settings .................................................

4 MANAGING OBJECT REPOSITORY .....................................

5 CALL TO FRAMEWORK .............................................

6 USAGE OF KEYWORDS .............................................

7 TEST RESULTS FOR A KEYWORD-DRIVEN SCRIPT ..........................

8 KEYWORD-DRIVEN SCRIPTING WITH A QUALITY CENTER CONNECTION .......

8.1 Connecting Quality Center ...............................................

8.2 Resource Files in Quality Center .......................................

8.3 Execution from Quality Center .......................................

8.3.1 Test Results from QC ..........................................................



1 Keyword-driven Scripting
This document drives the settings and how to get started with keyworddrivenscripting in HP QuickTest Professional (QTP).

2 Creating New Test
A new test in QTP can be created from QTP or can be generated fromQuality Center (QC).

2.1 Test Creation in QTP
To create a new test, select File > New > Test or click on thetoolbar button. A blank test will be created. The test can then be savedin the preferred location.

2.2 Test Generation from QC
New QTP tests can be generated corresponding to a particular test case by following the below steps.
1. Launch QC and login with valid credentials.
2. Navigate to the desired test in the Test Plan area.
3. Select the test and click on the ‘Design Steps’ tab in the righthandpane.
4. Click the dropdown button. Select Quick Test.
5. A new test script will be generated for the selected test and stored in the QC Test Plan section. The test can be accessed by selecting File > Open > Test or by clicking the toolbar button and navigating to the corresponding location in QC.

3 Test Settings for Keyword-driven Scripting

With the keyword-driven approach, the entire script is developed with keywords. The script is developed in a spreadsheet that is interpreted by the main driver script, which then uses the function library to execute the complete script. The QTP Settings.vbs file can be used to easily perform the test settings that are needed before proceeding with the Keyword-driven Scripting. This file associates the Function libraries, recovery scenarios, Environment Variables and the Object Repository files that are needed for a script. The QTP Settings file needs to be customized before usage. Edit the.vbs file in notepad and make the necessary changes (mentioned below) in the ‘Input Data’ section of the file.
1. Function Libraries – Specify the path where the Framework Files, Common Functions and the User Defined Functions are stored.
2. Recovery Scenario File - Specify the path of the file where the Recovery scenarios are placed.
3. Recovery Scenarios Name - Specify the names of the Recovery scenarios that need to be associated to the test script.
4. Environment File - Specify the path of the xml file for the Global Environment Variables.
5. Object Repository files - Specify the path of the Object Repository.
Open the test script in QTP for which the settings are needed and double click on the QTP Settings.vbs file. This file will perform the preferred settings automatically. If there are multiple items of libraries, object repositories or global variables file, they can be specified as an array separated by ‘,’ Set the Flag envi_flag, recover_flag, repos_flag, library_flag to "Yes" if the corresponding files need to be associated to test, Else set it to "no"

libraries= array ("C:\WebFramework.vbs","C:\common functions.vbs")
recovery_file= "C:\recover.qrs"recovery_name=array("Scenario1","Scenario2")environment_file= "C:\Environment.xml"repository_name= array ("C:\repository1.tsr","C:\repository2.tsr")

'NOTE: Please set the Flag to "Yes" if the files are to be associated totest, otherwise set it to "no"envi_flag="yes"recover_flag=" yes"repos_flag=" yes"library_flag=" yes"
There should be just one Recovery file which holds all the Recovery scenarios. MultipleRecovery files cannot be used.There should be no unsaved tests currently open in QTP. The test script for which the test settings need to be done should be open in QTP.
3.1 Run Settings
On the Run tab of the Test Settings dialog,
1. The Run one iteration only radio button will be selected.
2. The Disable Smart Identification during the run session the check box will be checked.
3. The Object Synchronization timeout value will be set as 20 seconds.













3.2 Resources Settings
After the run settings are completed, the QTP Settings file associates the framework with the test script. Here, the path and the names of the framework files need to be specified in the QTP Settings file. The framework will be taken from the location specified and associated with the test as shown in the figure below.



3.3 Environment Tab Settings

QTP can insert a value from the environment variable list, which is a list of variables and corresponding values that can be accessed from the test. Throughout the test run, the value of an environment variable remains the same, regardless of the number of iterations, unless the value of the variable is changed programmatically in the script.Associating user-defined environment variables files with the test is handled by the QTP Settings file. The environment variables xml file will be taken from the path specified in the QTP Settings file and be associated with the test.


4 Managing Object Repository

QTP must learn the interface of an application to be able to work with it. It does this by learning the application's objects and their corresponding property values and storing these object descriptions in an object repository file.
There are two types of object repositories:the shared object repository and the per-action object repository.
The same object repository file can be used for multiple tests if the tests include the same objects. Object information that applies to many tests is kept in one central location and the read-only copy of the repository is associated with the tests.
After the test settings are done, the QTP Settings file continues to associate the specified shared object repositories with the test. The objects from the shared repository will be uploaded and made available for the tests.



5 Call to Framework

The call to Keyword_Driver() needs to be specified in the Expert View as shown below. This will call the framework file associated with the test and perform the actions by interpreting the keywords specified in the data table.

6 Usage of Keywords

The keywords should be entered in the global sheet of the data table of the test according to the syntax. To access the data table, choose View > Data Table or click on the toolbar button. Below is an example of a simple keyword-driven scripting.


7 Test Results for a Keyword-driven Script
Test execution results can be viewed and analyzed as soon as the run session ends. To access the test results, choose Automation > Results or click on the toolbar button. The Results window will be displayed.


8 Keyword-driven Scripting with a Quality Center Connection




8.1 Connecting Quality Center
An QC connection needs to be established if the test, or the object repository, framework, or the environment variables are stored in QC.
Follow the steps given below to connect to QC.
1. Choose Tools > Quality Center Connection or click the Quality Center. Connection toolbar button . The Quality Center Connection dialog box opens.
2. In the Server box, type the URL of the Web server where QC is installed.
3. In the Server connection area, click Connect. After the connection to the server is established, the server's name is displayed in read-only format in the Server box.
4. In the Domain box, select the domain that contains the QC project.
5. In the Project box, select the project you want to work with.
6. In the User name box, type a user name for opening the selected project.
7. In the Password box, type the password for the selected project.
8. In the Project connection area, click Connect to connect QTP to the selected project.

After the connection to the selected project is established, the fields in the Project Connection area are displayed in read-only format. To automatically reconnect to the QC server and the selected project the next time you open QuickTest, select the Reconnect on startup check box.

8.2 Resource Files in Quality Center
The resource files such as Framework Files, Shared Object Repositories, and Environment Variables that are associated with the test can be stored in QC and obtained during test execution.Function libraries of the file type .vbs, environment variables of file type .xml, and object repositories of file type .tsr can be placed in the attachment section of the Quality Center Test Plan area and associated with the test.

8.3 Execution from Quality Center
Test scripts can also be executed from QC. The test results will be stored along with the test scripts and launched from QC. Before executing tests from QC, QTP has to be instructed to allow other HP products run tests. To do this, select Tools > Options in QTP. In the Run tab of the Options dialog, check the ‘Allow other HP products to run tests and components’ check box.
To execute test scripts from QC,1. Login to QC with valid user ID and password.2. Select the test or tests from the ‘Test Lab’ area.3. Click on the button in the right-hand pane.4. The Automatic Runner window will be displayed with the selected tests.5. Select the host machine on which the test needs to be run from the Run on Host field.6. Click the button to run only the highlighted test or the button to run all the selected tests.


8.3.1 Test Results from QC
For the tests run from QC, results can be accessed by double-clicking on the test name in the Test Lab and clicking on the Launch Report button in the Test Instance Properties dialog. Test results related to every execution instance will be available in QC. Highlighting the specified instance and clicking on Launch Report will display the Results Summary window corresponding to the selected instance.

2 comments:

abc said...

Great Stuff Rohit,

I am really impressed to find all the important stuff at one location.

Keep up the good work !

Thanks and regards,
Kishore

Anonymous said...

When i write Call Keyword_Driver()in Action 1 ,Its giving type mismatch error and how to associate QTPsetting.vbs file to action 1. Please clerify