Home > Software engineering >  Karate- Good way to send custom headers with each request
Karate- Good way to send custom headers with each request

Time:10-04

I have a scenario where I am doing a GET call and on my table I have parameters defined. Now for the headers, I want to purposefully send incorrect values to make sure the test fails as expected. Not really sure how to do it though.

I have the following setup:

        * table input
            | machine    | version | osSystem | status |
            | machineName| version | windows  | 401    |

My secondary file that the above calls on, looks like this:

        Given url env
        And path path
        And header Content-Type = 'application/xml; charset=UTF-16'
        And header Accept = '*/xml; charset=UTF-16'
        And header key = key
        When method GET

In above, I want to send bogus values for "key" header. Total of six bogus values (random alpha string, random number string, random alphanumerical value, random guid, etc). I have obviously tried entering the values as a json under "and header key = {}" but how do I make each request run EACH header per request, instead of running them all in one request?

Thank you in advance!

CodePudding user response:

Try this example and observe how it works, it will answer all your questions:

Scenario Outline:
* url 'https://httpbin.org/anything'
* header foo = header
* method get

Examples:
| header |
| one    |
| two    |

And for an alternate way to "loop" refer to this answer: https://stackoverflow.com/a/69422451/143475

  • Related