0

enter image description here

In the below picture, I have given assertion value as it is(Used response) ..it is working.

Whereas how to use "data" for assertion here...I tried in the same way but i got failed response.

Please help me out some one.

Rao
  • 20,781
  • 11
  • 57
  • 77
Satheesh
  • 87
  • 1
  • 8
  • Can you post the json string instead of image? – Rao Aug 18 '16 at 16:38
  • What is the expected output? are you looking for `userId` value i.e., 65? or just **JsonPath Count** of `data`? If `data` count, then have you tried `$.response.data` ? – Rao Aug 18 '16 at 16:50
  • { "task": "userLogin", "response": { "code": 0, "status": "success", "error_message": "", "success_message": "", "data": { "userId": "65", "username": "indian", "email": "test@gmail.com", "token": "b0aef6139ffdc1041e01f7587a0dcf61", "userType": "trial", "profile_picture": "test.png" } } } – Satheesh Aug 19 '16 at 05:47
  • Failure response:{ "task": "userLogin", "response": { "code": 1, "status": "error", "error_message": "invalid userid or password", "success_message": "", "data": "" } } – Satheesh Aug 19 '16 at 05:48
  • You have provided two responses. But you have not mentioned what you wanted to verify? – Rao Aug 19 '16 at 05:51
  • Rao, please tell me how to handle assertion property content according to the above responses..... – Satheesh Aug 19 '16 at 05:53
  • Ok fine....now I wants to check whether "data" displaying or not? if i give right credentials details are displayed as i mentioned 1st response......If i give wrong credentials details are not displayed as i mentioned 2nd response – Satheesh Aug 19 '16 at 05:57
  • in JASON path expression i give $.response.data ....then I give 1 what would be happened if 0 what would be happened.Please explain it how? – Satheesh Aug 19 '16 at 06:09
  • I believe groovy script suits better in your case as you wanted to verify the response contents conditionally. – Rao Aug 19 '16 at 06:45
  • Please edit your question and all full details there instead of comments. – Rao Aug 19 '16 at 06:48

1 Answers1

0

Have you tried parsing response in script assertion and asserting

 import groovy.json.JsonSlurper 
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText(response)
assert json.response.data!=null
user1207289
  • 3,060
  • 6
  • 30
  • 66