4

Karate: I would like to assert to match parts of response

I am getting the following response: 12:10:33.960 [print] Kyc Status changed from NotStarted to Accepted.Reason: Output Address AddressLine : 6927 14TH AVE

But I would like to only make assertion to match part of the response. e.g.: "Kyc Status changed from NotStarted to Accepted."

S Keleta
  • 77
  • 1
  • 5
  • It's a response of content type `text/plain`? `match response contains` allows to test if the response contains text elements. – Peter Oct 22 '19 at 13:22
  • Thank Peter for quick response, Yes, the response is text. Can I do partial match instead of the entire text? – S Keleta Oct 22 '19 at 14:18

1 Answers1

1

The following examples should solve your problem:

    Scenario: Matching text
      * def yourResponse = "12:10:33.960 [print] Kyc Status changed from NotStarted to Accepted.Reason: Output Address AddressLine : 6927 14TH AVE"
      * match yourResponse contains "NotStarted to Accepted"
      * match yourResponse !contains "does not contain"
      * assert new RegExp("NotStarted to Accepted").test(yourResponse)

Needless to say, that you can use any regex with the assert new RegExp construct.

Peter
  • 4,752
  • 2
  • 20
  • 32
  • Thanks Peter, it worked. I am fairly new with Karate Framework but I am really enjoying the tool and support – S Keleta Oct 24 '19 at 00:31
  • If you like karate, you have to check out vscode and the [vscode karate runner](https://marketplace.visualstudio.com/items?itemName=kirkslota.karate-runner) with the new debug feature! – Peter Oct 27 '19 at 19:33
  • assert new RegExp is not working for version 1.1.0 @Peter kindly suggest what other way can we do partial match – NagaRaj Jul 28 '22 at 04:00