Tuesday 15 January 2013

Using Excel to Build QTP Tests and Test Sets in Quality Center

This post will show how you can use Excel VBA to automatically create a QTP Test in Quality Center and then automatically assign the test to a test set. I have used this in one of my frameworks to represent Excel keyword driven test cases with QTP driver tests in QC, and automatically build test labs linking to the tests. Essentially it is automating the QC test plan and test lab builds.

Firstly I would like to put a few caveats in place:
  • This is just a proof of concept release. Please feel free to take the spreadsheet and develop it for your needs but I won't be able to support it for you. If you get stuck, start debugging the VBA and looking at the OTA documentation.
  • I have written functions to encapsulate Quality Center OTA calls. For some reason these can be a big buggy, so if the OTA calls fail you usually need to close Excel completely and then reopen it.
  • If you're testing this out remember to delete the tests & test sets created between each run, otherwise the code will throw some warnings.

The spreadsheet is a two step process:
  • It copies a known QTP test to a location in the test plan and then renames it. This creates a unique version of the test.
  • Then it creates the test lab and associates the QTP test to it.

Here's how to do it:
  • First of all download the spreadsheet from this link and open it in Excel (ensure macros are enabled). 
  • In Excel open up the VBA editor (Alt + F11) 
  • Open the module "modBuilder" and find the function called "Builder".
  • You will need to edit the line and change these values with your own QC setup:
If Not ConnectToQC("YOURSERVERNAME", "YOURDOMAIN", "PROJECTNAME", "USERNAME", "PASSWORD") Then
  • Return to the Excel workbook. Each row represents a test that will be created and added to a test set. You need to ensure that:
    • The template path and template name have been defined (columns A and B). These will point the code at an existing QTP test in the test plan.
    • Define the location where the new test will be created (columns C and D).
    • Define the test lab path and test set name where the new test will be created (columns E and F).
Once this is all setup click on the "Build" button and your tests and labs will be built!