cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing results from other steps - How to make context expand short?

SOLVED
rajs2020
Frequent 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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: Accessing results from other steps - How to make context expand short?

Try changing from

 

context.expand('${${row}/EMPLOYEENAME[1]}')

 

to

context.expand('${' + row  + '/EMPLOYEENAME[1]}')


Regards,
Rao.

View solution in original post

3 REPLIES 3
nmrao
Community Hero

Re: Accessing results from other steps - How to make context expand short?

Try changing from

 

context.expand('${${row}/EMPLOYEENAME[1]}')

 

to

context.expand('${' + row  + '/EMPLOYEENAME[1]}')


Regards,
Rao.

View solution in original post

sonya_m
Community Manager

Re: Accessing results from other steps - How to make context expand short?

Thank you Rao!

@rajs2020 Does this help?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
aaronpliu
Frequent Contributor

Re: Accessing results from other steps - How to make context expand short?

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

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors