0

I have API and lot of parameters there. I am using context to get value of particular parameter into groovy script.

But context returns me null for array parameters or parameters which are based on id.

Success

  • context.title
  • context.name

Failed to get value

  • context.location[] , context.location[id]
  • context.department[], context.department[id]

In API, I pass location and department IDs to get data.

For ex : location[id] = 556d6dDRE666deda5c

So how can I get value of parameters using groovy where parameters are either array or has ids.

7
  • Do you mind showing the data and which value you want to access? Commented Mar 7, 2017 at 13:03
  • @Rao - Added sample data if that can help. Commented Mar 7, 2017 at 13:35
  • Thank you for the update. Would appreciate if the text response can be added, you may keep the structure and put dummy values. Because, solution may vary depends on the response. By the way, what data you want to retrieve? skills? Commented Mar 7, 2017 at 13:40
  • @Rao- Yes I want to retrieve skills and location id. location has unique id that's it. Commented Mar 7, 2017 at 13:44
  • Can't find location in the visible data that you provided. Please add text response so that solution would be tested before answering. Commented Mar 7, 2017 at 13:49

1 Answer 1

1

You use the below Script Assertion based on the data provided.

//Check the response is not empty
assert context.response, 'Response is empty or null'

//Define expected values
def expectedLocationId = 'Your value here'
def expectedSkills = ['.NET']

def json = new groovy.json.JsonSlurper().parseText(context.response)

log.info "Skills : ${json.data.skills}"

log.info "Location id : ${json.location.id}"

//Assertions:

assert expectedLocationId == json.location.id, 'Location id not matching'
assert expectedSkills == json.data.skills, 'Skills not matching'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.