-1

With Karate API tests, I would like to print the request and reponse only when the test fails. How can I achieve that in karate.

Consider the below scenarios

Feature: Validate Addition.
  Background:
  Scenario Outline: Verify Addition
    * def sum = <num1> + <num2>
    And match sum == 10
    * print "number1:" + num1 + " number2:" + num2
    Examples:
      | num1 | num2 |
      | 5    | 5    |
      | 7    | 3    |
      | 3    | 8    |
      | 1    | 5    |
      | 1    | 9    |

In the above scenario I get the print for every iteration. Is it possible to print the numbers only when the match fails.

I think it would be more efficient if we can have such option.

Sourabh Roy
  • 159
  • 1
  • 18

1 Answers1

0

Short answer is that it is not possible. You can try contributing code to make this happen. Or maybe you should use REST-assured or Selenium - those sound more like a good fit for you, based on all your questions.

One thought is that you can switch off all logging by making the levels ERROR etc. and then write some custom hook. Refer to hooks here: https://stackoverflow.com/a/60944060/143475

Also refer to how to create custom reports here: https://stackoverflow.com/a/66773839/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248