Forum Discussion

MKV's avatar
MKV
Contributor
6 years ago

how to store data source values in array

How to store the data source output in an array without the values being overwritten.

 

My XML datasource results in 5 datas - price_discountCode,price_taxWaived,comm_notifEmail,price_creditdelay,comm_smsNumber

 

I try to store these 5 values in an array using groovy. My Groovy to store the data is as below:

 

def DSrowcount = testRunner.testCase.testSteps["XML_DataSource_AttributeName"].rowCount
log.info "Total rows of DS output:: " +DSrowcount

def ds = testRunner.testCase.getTestStepByName('XML_DataSource_AttributeName')
def attributename, attributeid, attributevalue = ""
def WS_AttributeNameList = []
def Namelist=[]
def WS_AttributeIdList = []
def WS_AttributeValueList = []

for (row in 1..DSrowcount)
{
attributename = ds.getPropertyValue('attributeName')

WS_AttributeNameList.add(attributename )
}
log.info "AttributeNames are: " +WS_AttributeNameList

 

Expected array output:

[price_discountCode, price_taxWaived, comm_notifEmail, price_creditdelay, comm_smsNumber]
Actual array output:

[comm_smsNumber, comm_smsNumber, comm_smsNumber, comm_smsNumber, comm_smsNumber]

 

Please help to resolve.

1 Reply

  • aaronpliu's avatar
    aaronpliu
    Frequent Contributor

    you want to get property name, but I did not understand what property you fetch from below code snippet

    for (row in 1..DSrowcount)
    {
    attributename = ds.getPropertyValue('attributeName')

    WS_AttributeNameList.add(attributename )
    }

     

    Maybe you needs to fetch all properties of data source and then loop to get all property name and add them into an array if needs.

     

    //step 1 - declare object of test step

    def teststep = testRunner.testCase.getTestStepByName("StepName")

    //step 2 - fetch speficied steps' properties

    def properties = teststep.getProperties()

    //step 3 - loop

    def alist = []

    for(key in properties.keySet()){

         alist << key

    }

    log.info alist