cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get parameter to pass through

SOLVED
Highlighted
Frequent Contributor

Cannot get parameter to pass through

I have a test shown in the screenshot. Its data driven and requires several API's to be hit to collect the right ID's to then make the final request.

In the below code (From the parameters groovy step), I get the 'expectedMatchingValue' from the TestData step.

I then get the response from the call made in the 'GetTest' step.

I then try to look at this response and find the ID that matches the value of the 'expectedMatchingValue' ('TestName').

 

I cannot get it to work though. It always returns a blank value.

I can make it work if I add an assertion step with the 'Gettest' call, but its not a true assertion so trying to split it out and put it into its own Groovy step.

 

ANy help is really appreciated.

 

 




/** * Script Assertion for REST Request test step **/ //Change the value for below statement as needed def name = context.expand( '${EditTestData#Name}' ) def expectedMatchingvalue = name assert context.'${GetTest#Response}', 'Response is empty or null' //def json = new groovy.json.JsonSlurper().parseText(context.response) def json = new groovy.json.JsonSlurper().parseText(context.'${GetTest#Response}' ) context.testCase.setPropertyValue('TESTIDNEW', json.value.find {it.TestName == expectedMatchingvalue}?.Id?.toString())
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Cannot get parameter to pass through

Hey @endorium 

 

in the line 

assert context.'${GetTest#Response}', 'Response is empty or null'
//def json = new groovy.json.JsonSlurper().parseText(context.response)

aren't you missing the word a word after 'context.' in the assertion?

 

e.g.

 

assert context.expand('${GetTest#Response}'), 'Response is empty or null'
//def json = new groovy.json.JsonSlurper().parseText(context.response)

??

 

ta,

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: Cannot get parameter to pass through

Hey @endorium 

 

in the line 

assert context.'${GetTest#Response}', 'Response is empty or null'
//def json = new groovy.json.JsonSlurper().parseText(context.response)

aren't you missing the word a word after 'context.' in the assertion?

 

e.g.

 

assert context.expand('${GetTest#Response}'), 'Response is empty or null'
//def json = new groovy.json.JsonSlurper().parseText(context.response)

??

 

ta,

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

Highlighted
Community Manager

Re: Cannot get parameter to pass through

Great observation richie! Smiley Happy

 

Hi @endorium, have you tried adding a word after context like Richie suggests? Did it improve your situation? 


Sonya Mihaljova
Community and Education Specialist
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
The new challenge is here!

Create a script to сhange an XPath Match assertion to a JSONPath Match assertion for the TechCorner tag!


Scripts created in July:
- A script to generate an email when an assertion fails
- A script to change the request body before sending it to the server
Top Kudoed Authors