Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to extract the value of one of the key value pairs in request to be asserted

Tags:

karate

peter had provided me a solution to use karate 0.9.3 to apply assertion from examples

Trying to do some assertion from request, which will be present in response

i was wondering if it is possible to assert a value from request instead of full request.

**Background:**
*  configure headers = read('classpath:merchantServiceheaders.js')

   Given url MservUrl 
   And path 'XXXXXX'

   And request Data
   When method POST 
   Then status 200 
   And match response != null 
   And match $ contains {serviceName: 'XXXXX'Service', responseMessage: 
   'Success' }
   And match each $.clauses..responseMessage == 'Success'
   And match each $..predicate != null
   And match each $..predicate == '#present'
   And match each $..predicate == '#regex [^0-9]+[0-9]*$'
   And match $..predicate contains Data.clauses.subject

   Examples: 
   |Data!                                               |
   |'{"clauses":[{"subject":"XXXX","predicate":"999999"}, 
   {"subject":"XXXXX","predicate":"99999"}]}'|

what i am trying to do is on the And match $..predicate contains Data.clauses.subject

is that possible?

like image 297
Sadiq K Avatar asked Mar 02 '23 22:03

Sadiq K


2 Answers

Yes, it is very much possible if Data is defined as a variable. But note that $..predicate will always be a JSON array: https://github.com/intuit/karate#get-plus-index

If you want help, please create a proper simple working example.

like image 133
Peter Thomas Avatar answered May 11 '23 10:05

Peter Thomas


Sample Code:

Feature: Validation

    Scenario:

        * def resp = {predicate : "4325325456545646"}
        * def data =
            """
            {
                "clauses": [
                    {
                        "subject": "5432154321543210",
                        "predicate": "4432154321543210"
                    },
                    {
                        "subject": "4325325456545646",
                        "predicate": "4325325456545646"
                    }
                ]
            }
            """
        * def sublist = get data.clauses[*].subject
        * print sublist
        * match sublist contains resp.predicate
like image 23
Neodawn Avatar answered May 11 '23 09:05

Neodawn