Sunday, May 20, 2012

Passing Parameters between QTP tests stored in Quality Center

In our recent project we had a requirement of passing some captured values in one test to another test in sequence of execution during runtime. We needed a solution which took lesser time to be implemented and tested, while satisfying our need to integrate 02 test instances in the test lab of Quality Center without getting dependent on other external data sources/utilities such as flat files, excels and file system object.



  1. Create a Test with Test Input Parameters using Test Settings
http://farm7.static.flickr.com/6143/5955598728_2fb7fe89a0_b.jpg
  1. Create Action Input Parameters in desired Action using Action Properties
http://farm7.static.flickr.com/6128/5955038667_c5703a5a90_b.jpg
  1. Link Above created Action and Test Parameter Using Action Call Properties
http://farm7.static.flickr.com/6007/5955039561_71113d0531_b.jpg
It is mandatory for us to link Action and Test Parameters as shown above, so that we can access the test parameters in an Action like below
ValueofTestParam = Parameter("ActionParam1")
Then Save the test in Test Plan Module. Ensure that your QTP is connected to QC
  1. Create a Test Set and Drag test in Test Lab Module of Quality Center Using Select Tests Tab
Now the Dragged instance of our test should be capable of recieving values from any other code/test. Have a look at the properties [3] of the dragged instance.
http://farm7.static.flickr.com/6150/5955039317_bf50e2474b_b.jpg
  1. Code in a common library
  1. Access Test Instance and its properties using OTA API
'Code to access the next test instance in Execution Flow
'Not a very clean code, please take care of declarations

Set TDC = QCUtil.QCConnection
set TSfact = TDC.TestSetFactory
Set TreeManager = TDC.TestSetTreeManager
Set tsFolder = TreeManager.NodebyPath("Root\Pathto\YourTestSetFolder")
Set TestSetList = tsFolder.FindTestSets("YourTestSetName")
Set theTestSet = TestSetList(1)
set TSTestFact = theTestSet.TSTestFactory
Set TestSetTestsList = TSTestFact.NewList("")

' You can take the other values as required in your framework
Inst = 1
TestName = "GettingParamTest"
InstanceName = "[" & Inst &"]" & TestName

For Each myinstance in TestSetTestsList

If Ucase(Trim(myinstance.Name)) = Ucase(Trim(InstanceName)) Then
        'I have got my instance
        Set MyTestInstance = myinstance
End If
  1. Study the xml format of automaion parameters stored in Quality Center
ExecutionParams property of a test instance has following xml representation
http://farm7.static.flickr.com/6147/5955039015_bd153103ac_b.jpg

<?xml version="1.0"?>
<Parameters>
        <Parameter>
                <Name><![CDATA[TestParam1]]></Name>
                <Value><![CDATA[ParamValue1]]></Value>
                <Name><![CDATA[TestParam2]]></Name>
                <Value><![CDATA[ParamValue2]]></Value>
        </Parameter>
</Parameters> 
  1. Plan modification of test instance parameters' values during runtime
ExecutionParams property of testinstance object returns a string(which is above mentioned xml )and the property is writable too.
NewParamsAndValues = Array("TestParam1>NewParamValue1","TestParam2>NewParamValue2")
OriginalParams = MyTestInstance.ExecutionParams

ModifiedParams = GetModifiedParams(OriginalParams,NewParamsAndValues)
' I am not writing the function GetModifiedParams in the example| You can write
' your own logic of manipulating the strings and values

MyTestInstance.ExecutionParams = ModifiedParams

print MyTestInstance.ExecutionParams
  1. How modified values will persist ?
Once you print MyTestInstance.ExecutionParams it will show the modified values for the test parameters, but these values do not persist. And these modified values need to persist for the next test instance to pick up in execution flow, Therefore We need to use post and refresh method ofMyTestInstance object.
MyTestInstance.Post()
MyTestInstance.Refresh()

No comments: