There are 4 most popularly used automation frameworks.
- Modular
- Data driven
- Keyword Driven
- Hybrid
First 3 frameworks have their own pros and cons. Hybrid framework is the combination of all 3 by using all the pros and minimizing the cons.
In this post, I would like to show how I have implemented my hybrid automation framework using QTP for one of the projects.
Folder Structure:
My folder structure is as given below.
- data – contains all the test data/expected files to be compared/files to be uploaded for testing purposes.
- lib – contains reusable application independent jar/dll
- objectrepository – properties to identify the elements in the application. [I have used a lot of descriptive programming. But I also like to keep the test identification properties away from the test script.]
- functions – VBScript / Javascript functions/Business actions.
- properties – test environment/database details / any test execution specific details.
- tests – Spreadsheet containing all the automated test cases details & keywords to be called.
- suites – test suites which contains test case numbers to be executed.
- output – it has sub folders for storing the result files, log files, any files to be downloaded while the test is running.
- runner.exe – an executable – driver script which launches QTP & executes the test
Lib Folder:
If I need to create some libraries which is not going to be application dependent, then i write that in .net instead of VBScript. Because We can write better code in .Net, it runs faster, has many reusable libraries, OOPs support, better error handling than VBScript.
Ex: I have below utilities created.
- ExcelUtil – To read spreasheet, compare etc
- JSONUtil – to read/write files
- ReportUtil – To create custom execution report once the test execution is complete.
- DBUtil – To connect to the DB & execute queries
- SMTPUtil – To send emails
- IMAPUtil – To read emails & extract the content
- ImageUtil – To create/compare images
- ChartUtil – To create charts for the given data
- PDFUtil – To read/write/compare PDF files
Properties Folder:
This folder contains a default properties file & an environment specific property file.
Each property is set as Environment Variable for QTP.
Functions Folder:
These are all application specific business actions written in VBScript.
Ex: I have below action keywords to execute some business functionalities specific to my application under test.
- CREATE_ORDER – to create an order for an user
- VIEW_ORDER – to view an existing order
- EDIT_ORDER – to edit an existing order
- DELETE_ORDER – to delete an existing order
- CREATE_USER – to create user
- SEARCH_USER – to search for an user
Above high level business action/keywords are QTP/Selenium automated test scripts. Whenever these keywords are called, the corresponding test script is executed.
For Ex: It could be something like this.
Function CREATE_ORDER ' select product for the given product code ' click on order button ' enter payment details ' checkout ' check for the conformation End Function
Tests Folder:
It contains a spreadsheet in which we add the automated test cases.
TestCase sheet:
It contains list of all the testcases for the application. It contains the test case ID, test description & corresponding business actions to be executed. By calling these actions in the given sequence, we get the business flow verified.
For Ex: For TC001, We need to create an user & order a product. So we call 2 actions – CREATE_USER & CREATE_ORDER. To order different products, the same function is called as the business flow is same and only the product is different (Data-driven). So we create another test case, TC002 – We call those 2 actions again.
To get the testdata for the action, driver reads action-data mapping sheet.
For Ex: Below sheet shows that for CREATE_ORDER business action , it can find the test data in the ‘OrderInformation’ sheet.
Driver goes to ‘OrderInformation’ sheet and gets the test data from this sheet by using the testcase ID. In the below image, TC001 & TC002 have different test data. Eventhough TC001 and TC002 have the actions, they use different test data and tests different products.
Suite Folder:
Test case spreadsheet contains all the possible test cases for the application. Suite file contains group of test cases to be executed for a functionality.
For ex: I might have 1000 automated test cases in total from different modules of the application. But i might be interested in running only 100 testcases specific to ‘order’ module as there could be a recent change in the particular module of the application. So i create a suite file which contains only order related cases to execute.
Sample Suite File:
How It Works:
- Runner.exe: It expects 3 parameters.
- Environment in which all the tests need to be executed (like PRODUCTION/PPE/QA…)
- Browser (IE/FF/Chrome)
- Suite (name of the suite file which contains the test numbers to be executed.
It invokes the QTP using its Automation Object Model & loads the environment variables, starts running the QTP – It also keeps monitoring the execution, logs the results in the console.
Check here to log QTP result in the console.
- Driver:
- It reads test case IDs from the suite files.
- Using these ID, It gets the Business Action Keywords to be executed from the ‘Tests’ spreadsheet.
- For each Business Action Keyword, It reads the test data
- Once the test data is read, It calls the Keyword.
Report:
The report utility creates a nice HTML as shown here. [I created the .net library to create the HTML report – but I used a CSS file to format the HTML from a blog long back. I forgot the site. Credit for the css should go there]
Notification:
Once the execution is complete, It sends out a detailed information to the email addresses given in the property files. I use Jenkins plugin to send the emails. I also use another Jenkins plugin to send SMS notifications to your mobile device.
Summary
My aim was to give you a high level idea about the hybrid automation framework I have implemented. Please leave a comment in case of any questions / suggestions.
If you are interested in implementing something similar for your organization, Please refer to below posts of TestAutomationGuru.
- QTP/UFT – Jenkins Integration
- Passing Parameters to UFT test from Jenkins
- Github / SVN integration for UFT scripts