Showing posts with label Automatically Add Resources to a QTP Test. Show all posts
Showing posts with label Automatically Add Resources to a QTP Test. Show all posts
Wednesday, December 17, 2008
Automatically Add Resources to a QTP Test
Automatically Add Resources to a QTP Test
Working with external function libraries (e.g., vbs files) is a common practice among advanced QTP practitioners. This feature of QTP enables developers to encapsulate functionality that needs to be reused in the form of functions, subroutines, and even classes. It is even possible to set the currently loaded function libraries as default, and hence every new test would "inherit" these libraries as the project infrastructure. Building automated tests based upon such a robust infrastructure with such components is a highly recommended practice that makes the developer’s work highly efficient.
Nevertheless, QTP doesn’t provide a user friendly way to add such resources to a test. The Test Settings Resources Tab allows the user to add just one file at a time, hence making this a tedious task. Moreover, the list view of function libraries is cumbersome, requiring one to scroll up and down to verify the existence of a specific file, and if these disadvantages are not enough, it also does not support adding the contents of an entire folder. These shortcomings make the task of adding resources time-consuming. Because the projects I lead require the use of hundreds of such function library files, I decided to help-up my team members by automating this process. I had prepared a basic script more than a year ago for this purpose exploiting QTP automation object model (AOM.), but I wanted to improve the script to make it more generic and scalable.
To accomplish this feat I designed the process as follows:
1.Define the test you wish to configure;
2.Define the pathnames of the folders in which the function libraries are stored (can be relative paths);
3.Define whether the test resources should be emptied before adding the new ones;
4.Define whether you wish the test to run after configuration is done
5.Call the configuration script, which should do the following:
Launch QTP;
Open the required test;
Set the search folders in QTP options;
If required, remove function libraries from the test resources;
Add the function libraries located in the search folders to the test resources;
Save the test;
If required, run the test.
The mechanism is based on 4 files: QtpConfig.wsf, QtpConfig.ini, QtpConfig.bat and RunQtpConfig.bat. The mechanism assumes a standard folder structure which is, in any case, an advisable method to efficiently store the deliverables (function libraries, data files, etc.) of an automation project. The basic folder structure would be like avobe image.
Where AUT stands for Application Under Test, and the folder names are self-explanatory. This scheme enables us to store the QTP tests under the scripts folder and exploit the standard use of search folders by relative paths. In my projects I further use a similar folder structure for Common and Infra projects, which are used by all specific AUT projects. Note: QtpConfig.wsf and QtpConfig.bat are located in the Infra/scripts folder, and the attached files assume this fact for proper functioning. QtpConfig.ini just contains a variable to set the debug mode to true or false, and is located together with the previous two. RunQtpConfig.bat is located in the AUT/scripts folder.
I shall now explain the use of the three main files mentioned above (apart from the ini file which is obvious). QtpConfig.wsf is a Windows Script File written in VBScript; it does the actual QTP configuration work using QTP COM object. QtpConfig.bat is the batch file that calls QtpConfig.wsf while passing the relevant arguments. Finally, RunQtpConfig.bat is a batch file that calls QtpConfig.bat and passes the relevant arguments, which are: TestPathName, Folders, RemoveAllFirst and RunTest. These arguments instruct QtpConfig.wsf what to do and on which test, as described below:
TestPathName is the relative path of the QTP test to be configured.
Folders is a semicolon separated list of folders required to configure the search path of QTP and to find the relevant function libraries.
RemoveAllFirst is a boolean that indicates whether to remove all resources (libraries) before adding them anew.
RunTest is a boolean that indicates whether
Subscribe to:
Posts (Atom)