Item - Verify Element Property Value


#1

Can you help me with item - Verify Element Property Value?

In the new project, I created a test case with a POST request for a web service:

{

“request”:[

{

“Period”:“2018-06-11T16:11:20.0904778Z”,

“ExternalContactId”: “854”,

“Plan”: “15”

}

]

}

In the program Katalon, he does a good job.

Then I wrote a code that Katalon would output the response from the web service to which the request was sent:

def responseData = WS.sendRequest(findTestObject(‘1 POST from EditManagerPlanInfo Method’))

responseCode = responseData.getStatusCode()

println('Response Code: ’ + responseCode)

// response body

def responseText = responseData.getResponseText()

println('Response Text: ’ + responseText)

def jsonObject = new groovy.json.JsonSlurper().parseText(responseText)

// extract value from response body

// get origin attribute

def ip = jsonObject.origin

WS.verifyElementPropertyValue(responseData, ‘Key’, ‘11399’)

But, the test case is dumped with an error:

03-13-2018 11:52:32 AM - [FAILED] - Expected element property value ‘11399’ is not equal with actual property value ‘null’

03-13-2018 11:52:32 AM - [FAILED] - Unable to verify element property value (Root cause: Expected element property value ‘11399’ is not equal with actual property value ‘null’)

03-13-2018 11:52:32 AM - [END] - End action : verifyElementPropertyValue

03-13-2018 11:52:32 AM - [FAILED] - Test Cases/Dashboard - 1) Method FAILED because (of) Unable to verify element property value (Root cause: Expected element property value ‘11399’ is not equal with actual property value ‘null’)

03-13-2018 11:52:32 AM - [END] - End Test Case : Test Cases/Dashboard - 1) Method

Thus in the output text (responseText) there is a line with data, necessary to me:

03-13-2018 11:52:32 AM - [START] - Start action : Statement - println("Response Text: " + responseText)

Response Text: {“EditManagerPlanInfoResult”:{“Result”:1,“ResultCodeDescription”:[{“Description”:“Неверный формат даты поля [EndDate]”,“ExternalContactId”:“854”,“Key”:“11399”,“Period”:“2018-06-11T16:11:20.0904778Z”},{“Description”:“Контакт с таким [ExternalContactId] не существует. Не найден Контакт [Contact] с внешним идентификатором [ExternalId] = 854”,“ExternalContactId”:“854”,“Key”:“11301”,“Period”:“2018-06-11T16:11:20.0904778Z”}]}}

Can you help with this problem?
Becouse there is string “Key”:“11399” from response at WS.

Thanks!


#2

The response contains an array of objects. You need to specify which index to locate “11399”. Since “11399” is located at index 0, try:

WS.verifyElementPropertyValue(response, ‘[0].Key’, ‘11399’)


#3

Joseph said:

The response contains an array of objects. You need to specify which index to locate “11399”. Since “11399” is located at index 0, try:

WS.verifyElementPropertyValue(response, ‘[0].Key’, ‘11399’)

I’m tried this method earlier. Outputs such an error:

Unable to verify element property value (Root cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer)


#4

Alex,

Could you paste here the result returned by the request?


#5

Alex said:

Joseph said:

The response contains an array of objects. You need to specify which index to locate “11399”. Since “11399” is located at index 0, try:

WS.verifyElementPropertyValue(response, ‘[0].Key’, ‘11399’)

I’m tried this method earlier. Outputs such an error:

Unable to verify element property value (Root cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer)

Can you try casting ‘[0].Key’ as a String?

WS.verifyElementPropertyValue(response, (String)’[0].Key’, ‘11399’)

If that doesn’t work, try converting ‘[0].Key’ to a String.

WS.verifyElementPropertyValue(response, String.valueOf(’[0].Key’), ‘11399’)

Just taking wild guesses at this point.


#6

Trong Bui said:

Alex,

Could you paste here the result returned by the request?

This massage returned by the request:

Response Text: {“EditManagerPlanInfoResult”:{“Result”:1,“ResultCodeDescription”:[{“Description”:“Неверный формат даты поля [EndDate]”,“ExternalContactId”:“854”,“Key”:“11399”,“Period”:“2018-06-11T16:11:20.0904778Z”},{“Description”:“Контакт с таким [ExternalContactId] не существует. Не найден Контакт [Contact] с внешним идентификатором [ExternalId] = 854”,“ExternalContactId”:“854”,“Key”:“11301”,“Period”:“2018-06-11T16:11:20.0904778Z”}]}}

From more readable view:

{

"EditManagerPlanInfoResult": {

    "Result": 1,

    "ResultCodeDescription": \[

        {

            "Description": "Контакт с таким \[ExternalContactId\] не существует. Не найден Контакт \[Contact\] с внешним идентификатором \[ExternalId\] = 854",

            "ExternalContactId": "854",

            "Key": "11399",

            "Period": "2018-06-11T16:11:20"

        }

    \]

}

}


#7

Joseph said:

Alex said:

Joseph said:

The response contains an array of objects. You need to specify which index to locate “11399”. Since “11399” is located at index 0, try:

WS.verifyElementPropertyValue(response, ‘[0].Key’, ‘11399’)

I’m tried this method earlier. Outputs such an error:

Unable to verify element property value (Root cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer)

Can you try casting ‘[0].Key’ as a String?

WS.verifyElementPropertyValue(response, (String)’[0].Key’, ‘11399’)

If that doesn’t work, try converting ‘[0].Key’ to a String.

WS.verifyElementPropertyValue(response, String.valueOf(’[0].Key’), ‘11399’)

Just taking wild guesses at this point.

From this code:

WS.verifyElementPropertyValue(response, (String)’[0].Key’, ‘11399’)

Outputs such an error:

Unable to verify element property value (Root cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer)

From this code:

WS.verifyElementPropertyValue(response, String.valueOf(’[0].Key’), ‘11399’)

Outputs such an error:

Unable to verify element property value (Root cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer)

I tried many ways, so I decided to ask for help :slight_smile:


#8

Alex said:

Trong Bui said:

Alex,

Could you paste here the result returned by the request?

This massage returned by the request:

Response Text: {“EditManagerPlanInfoResult”:{“Result”:1,“ResultCodeDescription”:[{“Description”:“Неверный формат даты поля [EndDate]”,“ExternalContactId”:“854”,“Key”:“11399”,“Period”:“2018-06-11T16:11:20.0904778Z”},{“Description”:“Контакт с таким [ExternalContactId] не существует. Не найден Контакт [Contact] с внешним идентификатором [ExternalId] = 854”,“ExternalContactId”:“854”,“Key”:“11301”,“Period”:“2018-06-11T16:11:20.0904778Z”}]}}

From more readable view:

{

"EditManagerPlanInfoResult": {

    "Result": 1,

    "ResultCodeDescription": \[

        {

            "Description": "Контакт с таким \[ExternalContactId\] не существует. Не найден Контакт \[Contact\] с внешним идентификатором \[ExternalId\] = 854",

            "ExternalContactId": "854",

            "Key": "11399",

            "Period": "2018-06-11T16:11:20"

        }

    \]

}

}

I placed the output in a JSON evaluator.

Try the following:

WS.verifyElementPropertyValue(response, ‘EditManagerPlanInfoResult.ResultCodeDescription[0].Key’, ‘11399’)

chrome_2018-03-16_08-16-17.png


#9

Joseph said:

Alex said:

Trong Bui said:

Alex,

Could you paste here the result returned by the request?

This massage returned by the request:

Response Text: {“EditManagerPlanInfoResult”:{“Result”:1,“ResultCodeDescription”:[{“Description”:“Неверный формат даты поля [EndDate]”,“ExternalContactId”:“854”,“Key”:“11399”,“Period”:“2018-06-11T16:11:20.0904778Z”},{“Description”:“Контакт с таким [ExternalContactId] не существует. Не найден Контакт [Contact] с внешним идентификатором [ExternalId] = 854”,“ExternalContactId”:“854”,“Key”:“11301”,“Period”:“2018-06-11T16:11:20.0904778Z”}]}}

From more readable view:

{

"EditManagerPlanInfoResult": {

    "Result": 1,

    "ResultCodeDescription": \[

        {

            "Description": "Контакт с таким \[ExternalContactId\] не существует. Не найден Контакт \[Contact\] с внешним идентификатором \[ExternalId\] = 854",

            "ExternalContactId": "854",

            "Key": "11399",

            "Period": "2018-06-11T16:11:20"

        }

    \]

}

}

I placed the output in a JSON evaluator.

Try the following:

WS.verifyElementPropertyValue(response, ‘EditManagerPlanInfoResult.ResultCodeDescription[0].Key’, ‘11399’)

Cool! It’s working. Thank you so much! :slight_smile: