rajs2020
4 years agoFrequent Contributor
Accessing results from other steps - How to make context expand short?
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?
Try changing from
context.expand('${${row}/EMPLOYEENAME[1]}')
to
context.expand('${' + row + '/EMPLOYEENAME[1]}')