Friday, January 2, 2009

Advanced scripting using OTA.

As we saw in OTA basics we were able to connect to any QC project in a matter of time. now once we have established connection with QC we can perform a variety of tasks. Before going for a long project let us divide it in smaller projects.
Think of normal everyday tasks in any software development organization using Quality Center for quality processes management. The day-to-day activities include daily builds, running basic tests, publishing reports.
We will take a large project called "AutoGenerator" which would perform following actions:
1) Verify build availability (assuming a build mail is received on build completion)
2) Kick start basic build verification tests (assuming the build is successful)
3) Execute the required tests (based on TestSets mentioned in QC)
4) Generate report (based on execution results)
5) Mail report

This is a long process which takes most of the time of any build engineer in any software organization and there are many dependencies due to which work may get delayed.
In simple words the project would work in minimizing these daily tasks by automating them.
The project would do wonders for both Dev and QA organizations as the test results would be available as the first thing in the morning and they can take approprite steps to cater it if anything goes wrong.

There are a lot of assumptions made while designing this project which are as follows:
1) The organization has a build process in place.
2) The build process also involves receival of mail using Outlook to intended recipents.
3) The organization uses QC for QA processes.
4) The organization uses QTP for automating their tests and scripts are saved in QC for execution.
5) Basic tests for verifying build are automated.
6) Reports are generated in Excel and published by mail.

Now let us divide this project in parts and have a look at one of them
Part 1 : Execute the required tests
Following is the code for same:
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
QCConnection.login ,
QCConnection.Connect ,
Set TestSetFact = QCConnection.TestSetFactory
Set tsTreeMgr = QCConnection.TestSetTreeManager
Set tSetFolder = tsTreeMgr.NodeByPath()
Set TestSetsList = tSetFolder.FindTestSets()
Set theTestSet = TestSetsList.Item(1)
Set gettestlist = theTestSet.TSTestFactory
Set TestSetlist = gettestlist.NewList("")
For Each gettest In TestSetlist
gettest.HostName =
Set TestSetlist = Nothing
Set Scheduler = theTestSet.StartExecution("")
Set execStatus = Scheduler.ExecutionStatus
Dim RunFinished, ExecEventInfoObj, TestExecStatusObj
RunFinished = execStatus.Finished
While RunFinished = False
Sleep 300000
execStatus.RefreshExecStatusInfo "all", True
RunFinished = execStatus.Finished
Set execStatus = Nothing
Set Scheduler = Nothing
Set TestSetlist = Nothing
Set QCConnection = Nothing

The code above assumes that you are running the suit on some specific Host machine which will need to be replaced at the mentioned location.
We will have a look at other part in the next section.