Forum Discussion

Toananas's avatar
Toananas
Occasional Contributor
5 years ago

Property Transfer Conditional

Hi guys,    I'd like to perform a conditional Property Transfer from one response to the next request. I need to select the first DefCategoriesDispo with the StatutDispo on true and send the CatCod...
  • nmrao's avatar
    nmrao
    5 years ago

    Toananas 

    For the first request (where you get the response and need to extract the data), add a script assertion with following snippet

     

    assert context.response, 'Response is empty or null'
    //Get DefCategoriesDispo first match with StatutDispo is true
    def catDispo = new XmlSlurper().parseText(context.response).'**'.find {it.name() == 'DefCategoriesDispo' && it.StatutDispo == true}
    
    //Extract data and save them into custom properties
    context.testCase.setPropertyValue('CATID', catDispo.CatId.text())
    context.testCase.setPropertyValue('CATCODE', catDispo.CatCode.text())

    In the next step where ever CatId, CatCode are needed

    use ${#TestCase#CATID}, ${#TestCase#CATCODE} respectively

     

    You can apply the same logic to the rest of the fields.

     

    Say for eg:

    <hit:Categ>${#TestCase#CATID}</hit:Categ>

     

  • nmrao's avatar
    nmrao
    5 years ago
    Sorry didn't check in detail. Thought you posted the solution using existing one.

    You got a trivial error. enclose O between single quotes like 'O'