Karate: How to Use Logical Control in Karate

Created on 22 Jun 2018  Â·  4Comments  Â·  Source: intuit/karate

Now I have a problem. Assume that before I request the A interface, I need to request the B interface and decide whether it needs to request the A interface based on whether the value returned by the B interface is null. How do I do this in karate? I read the document do not know if eval can meet my needs?

like this

`

get B response

  • eval if ( Bresponse == {} )
    path '……'
    path '……'
    `
question

Most helpful comment

I think I fell in love with karate

All 4 comments

@nuanyang233 anything is possible, please read this answer on Stack Overflow: https://stackoverflow.com/a/50350442/143475

the last line can be * eval if (condition) karate.call('some.feature')

Thank you, I still have a question. Does karate have shortcuts to help me get to the last element when using get to fetch elements from an array?

yes. actually this is easy in JsonPath: https://stackoverflow.com/a/45029709/143475

Also read the karate docs.

    * def list = [1, 2, 3, 4]
    * def last = get[0] list[-1:]
    * match last == 4

you can also use JS

    * def list = [1, 2, 3, 4]
    * def last = list[list.length-1]
    * match last == 4

I think I fell in love with karate

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhavilah picture mhavilah  Â·  4Comments

bAmrish picture bAmrish  Â·  3Comments

IsaoTakahashi picture IsaoTakahashi  Â·  3Comments

hascode picture hascode  Â·  3Comments

JuliaSv picture JuliaSv  Â·  5Comments