1

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!

hungryhippos
  • 617
  • 4
  • 15

1 Answers1

1

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you for the quick help. I really like the Scenario Outline solution, however, there is no way to add tagging to it correct? I.e I cannot call on it from a primary file, correct? – hungryhippos Oct 04 '21 at 03:49
  • 1
    @hungryhippos I highly doubt that tagging and calling is something you need to worry about for this kind of test, but anyway. I'm also feeling sad that all the documentation I write seems to be useless. answer to Q1: https://github.com/karatelabs/karate#tags-and-examples Q2: you can. why not ? – Peter Thomas Oct 04 '21 at 03:59
  • 1
    Thank you so much once again for the quick response. You have amazing documentation. It's just that I thought I had tagging all figured out. Didn't even think to look for if there can be other ways to tag things, which is so flexible and great. I apologize about the overlook there. – hungryhippos Oct 04 '21 at 04:35