Forum Discussion

yuraku's avatar
yuraku
Contributor
8 years ago

JsonPath Existence Match is valid even in case of wrong expected result

Hi.

 

in my case JsonPath Existence Match is valid even in case of wrong expected result. 

When i have true in expected result and false in response, assertion is passed

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Also maybe some one can help me to write correct script:

i need to check job status and only if status is true i need to go to other step, if false i need to run previous step again.

import groovy.json.JsonSlurper

def jsonSlurper = new JsonSlurper()

def response = testRunner.testCase.testSteps["Check Job Status"].testRequest.response.contentAsString
log.info(response)
def responseObject = jsonSlurper.parseText(response)

if (String.valueOf(responseObject.Successful).equals(false))
	testRunner.gotoStepByName( "Check Job Status")
	else
	testRunner.gotoStepByName( "Get Job Result")

Thanks in advance.

12 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Two things:

    1. It is not mentioned the problem with your script

    2. It looks almost right. But, based on the screen shot of the response, it is not clear if the value that you extracted is String or Boolean. May that would be causing.

     

    Try below change and see if that helps :

    Change from

     

    if (String.valueOf(responseObject.Successful).equals(false))

    To

    if ('false' == responseObject.Successful)

     

    • yuraku's avatar
      yuraku
      Contributor

      Thanks for your reply. But it doesn't work for me.

      This is my code:

       

      if ('false' == responseObject.Successful){
      	testRunner.gotoStepByName( "Check Job Status")}
      	else{
      	testRunner.gotoStepByName( "Get Job Result")}

      it still goes to the second step instead of first one.