Forum Discussion
appliedMagic
5 years agoOccasional Contributor
Hi,
you could achieve this with a bit of groovy scripting like this.
Create a new project, add a test suite and then add 3 new test cases (script, getSiteList and getSiteInfo).
Right-click on getSiteList and getSiteInfo and deactivate the test case.
Add a Soap-Request to getSiteInfo and getSiteList, set the appropriate soap-endpoint for each.
Add a groovy script to the test case "script".
It should look like this now:
Add the following code to the groovy script:
def getSiteInfo = context.testCase.testSuite.getTestCaseByName('getSiteInfo').getTestStepByName("request")
def getSiteList = context.testCase.testSuite.getTestCaseByName('getSiteList').getTestStepByName("request")
//add code here to change userName, password, custNbr if necessary
def userName = 'username'
def password = 'pwsd'
def custNbr = '288'
//set userName, password, custNbr
getSiteList.setPropertyValue('request',
"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bil="http://billing.xyz.cc/">
<soapenv:Header/>
<soapenv:Body>
<bil:getSiteList>
<!--userName-->
<arg0>""" + userName + """</arg0>
<!--password-->
<arg1>""" + password + """</arg1>
<!--custNbr-->
<arg2>""" + custNbr + """</arg2>
<!--lastModifiedDt-->
<!--<arg3>?</arg3>-->
</bil:getSiteList>
</soapenv:Body>
</soapenv:Envelope>""")
// fire request
getSiteList.run(null, context)
// get response
def root = new XmlSlurper().parseText(getSiteList.getPropertyValue('response'))
// iterate over all siteIds and fire request based on the siteId
root.'**'.findAll() {node -> node.name() == 'siteId'}.each { id ->
getSiteInfo.setPropertyValue('request',
"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bil="http://billing.xyz.cc/">
<soapenv:Header/>
<soapenv:Body>
<bil:getSiteInfo>
<!--userName-->
<arg0>""" + userName + """</arg0>
<!--password-->
<arg1>""" + password + """</arg1>
<!--custNbr-->
<arg2>""" + custNbr + """</arg2>
<!--siteId-->
<arg3>""" + id + """</arg3>
</bil:getSiteInfo>
</soapenv:Body>
</soapenv:Envelope>""")
//fire request for getSiteInfo
getSiteInfo.run(null, context)
//show result
log.info getSiteInfo.getPropertyValue('response')
// add more code here
// ...
}
If you either run the project, test suite or groovy script it should first request the site list and then iterate of every siteId and request further information for each.