Forum Discussion

endorium's avatar
endorium
Frequent Contributor
5 years ago

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())
  • 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

     

  • richie's avatar
    richie
    Community Hero

    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

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Great observation richie! :smileyhappy:

       

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