Forum Discussion
Hi Rao, then so select the first response with "True" or to select one of them randomly.
The selected CodeCat goes to <hit:Categ>?</hit:Categ>
Sure :
s<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hit="http://www.hitech.fr/"> <soapenv:Header/> <soapenv:Body> <hit:GetDispoSurAgence> <hit:CodeOrigine>?</hit:CodeOrigine> <hit:CodeAgence>?</hit:CodeAgence> <hit:Categ>?</hit:Categ> <hit:Depart>?</hit:Depart> <hit:Retour>?</hit:Retour> </hit:GetDispoSurAgence> </soapenv:Body> </soapenv:Envelope>
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>
- Toananas6 years agoOccasional Contributor
Thanks ! But I got now an error :
- HimanshuTayal6 years agoCommunity Hero
Hey nmrao :
It would be glad if you please share any documentation for tutorial for below code snippet:
def catDispo = new XmlSlurper().parseText(context.response).'**'.find {it.name() == 'DefCategoriesDispo' && it.StatutDispo == true}
what is the use of ** and also .find{} in this.
- nmrao6 years ago
Champion Level 1
Hope you read the comment along with the code snippet.
Suggest you to read groovy documentation.
- Toananas6 years agoOccasional Contributor
Hi,
I want to do the same with another Test suite, here's the assertion script :
assert context.response, 'Response is empty or null' // Permet de trouver la première catégorie avec une dispo def catDispo = new XmlSlurper().parseText(context.response).'**'.find {it.name() == 'CategorieDispo' && it.Statut == O} //Récupère la catégorie et la stock dans une custom property context.testCase.setPropertyValue('CATCODE', catDispo.CategorieGroup.text())
And here the request response :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <DispoResponse xmlns="http://www.hitech.fr/"> <DispoResult> <Demande> <StationDepart>U1194</StationDepart> <DateDepart>2020-05-18T10:00:00Z</DateDepart> <StationRetour>U1194</StationRetour> <DateRetour>2020-05-19T10:00:00Z</DateRetour> </Demande> <Categories> <CategorieDispo> <CategorieGroup>M1</CategorieGroup> <Statut>N</Statut> </CategorieDispo> <CategorieDispo> <CategorieGroup>M2</CategorieGroup> <Statut>N</Statut> </CategorieDispo> <CategorieDispo> <CategorieGroup>M3</CategorieGroup> <Statut>O</Statut> </CategorieDispo> </Categories> </DispoResult> </DispoResponse> </soap:Body> </soap:Envelope>
I want to transfer the <CategorieGroup>M3</CategorieGroup> if only the statut is O
Thanks !