Forum Discussion

mkhan031486's avatar
mkhan031486
Contributor
7 years ago
Solved

How can I add two values in a request that is taken from another response

I have two web services that I'm testing right now.    First webservice basically calculates taxes for different products. The second one actually adds the total taxes and makes a payment. For exam...
  • nmrao's avatar
    7 years ago

    mkhan031486,

     

    Here is the quick demo to extract and the sum the taxes. Note that this demo uses fixed xml. But, you may want it to be dynamic for each test request.

     

    Here you what you need to do:

     

    For the first soap request, add script assertion as shown below:

     

    assert context.response, 'Response is empty or null'
    
    //extract the tax and sum all of them
    
    def cTax = new XmlSlurper().parseText(conext.response)
    .'**'
    .findAll{it.name() == 'CreditTax'}
    .collect{it.text() as double}
    .sum() log.info "Total tax : $cTax" //Store the above cTax value at test case level custom property TOTAL_TAX context.testCase.setPropertyValue('TOTAL_TAX', cTax.toString())

     

     

    In the next request, use Property Expansion where the total tax is needed.

    For eg:

    <TotalTaxAmt currency="USD">${#TestCase#TOTAL_TAX}</TotalTaxAmt>