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
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
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

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
Enroll at the SmartBear Academy today and learn our products via exclusive video courses.