1

I have to test an API where I have to give various type of speech inputs with similar details in API request body. I can write these different speech using Scenario Outline and Example but I have to parameterize that speech also.

Consider below example:

  Scenario Outline: Validate identification
    Given url exampleURL
    And request {"message" : "<speech>"}
    When method post
    Then status 200
    Examples:
    | speech                     |
    | My name is John Doe and the ID is 12345|
    | I am John Doe and ID is 12345          |

Is there any way I can pick name and ID from somewhere else maybe from feature file or any external file?

mogli3
  • 43
  • 2

1 Answers1

0

Yes, refer to this example:

Feature: using a csv file for data-driven testing

  Scenario Outline: dynamic ${__num + 1}
    # dynamic outline comment
    * print 'row:', __row
    
    Examples:
      | read('data.csv') |

And in data.csv you have:

name,age
John,42
Jill,35

This will work. Please refer the documentation for @setup: https://github.com/karatelabs/karate/tree/master#setup

Here is another example: https://stackoverflow.com/a/76527245/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Actually I need to parametrize only name and ID like this - | My name is and the ID is | | I am and ID is | – mogli3 Jun 23 '23 at 06:14
  • @mogli3 no you can't inject variables into `Examples`, refer: https://stackoverflow.com/a/57291852/143475 - my advice is don't try to over-complicate things, just keep it simple – Peter Thomas Jun 23 '23 at 21:16