Say we get one row from a database and then we access that row in a groovy script. I see many test scripts which access multiple columns in the row like this:
context.expand('${GetRowFromDatabase#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/EMPLOYEENAME[1]}')
This is very long, ugly and repetitive. So, I would like to do something shorter instead, like this:
def row = 'GetRowFromDatabase#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]'
def employeeName = context.expand('${${row}/EMPLOYEENAME[1]}')
// get more columns here.
But, this does not work i.e. employeeName is empty. What is my mistake here? Is it possible to do this in ReadyAPI?
Solved! Go to Solution.
Try changing from
context.expand('${${row}/EMPLOYEENAME[1]}')
to
context.expand('${' + row + '/EMPLOYEENAME[1]}')
Try changing from
context.expand('${${row}/EMPLOYEENAME[1]}')
to
context.expand('${' + row + '/EMPLOYEENAME[1]}')
Thank you Rao!
@rajs2020 Does this help?
Hi @rajs2020 ,
I just recommended you to use JsonSlurper to parse your JSON response or XmlHolder to parse XML response.
Database query return a xml-like response, right? then you can try:
(Example)
def holder = new XmlHolder(response)
def node = holder.getNodeValues( "//div/a[@title='APIs']/@href" )
you would paste your sample response here if don't mind, using XPath to retrieve it
Thanks,
/Aaron
Subject | Author | Latest Post |
---|---|---|