Karate Data-Driven Testing
Karate Data-Driven Testing
In this tutorial, you will learn Data-Driven Testing using the Karate Automation Tool. In this example, we use the Examples table to drive a Scenario.
Data-Driven Testing
Sometimes, we want to run the same Scenario multiple times with different data sets. This is the benefit of automation testing over manual testing. It would be boring and tedious for a manual tester to repeat the same scenario multiple times.
Scenario Outline
Scenario Outline is the list of steps for data-driven testing using as an Examples and variables with <placeholder>.
Scenario Outline feature in same as in Cucumber for data-driven tests to run a Scenario with multiple sets of data. Scenario repeats itself multiple times replacing the values of the variable with Examples tables data. The Scenario would run multiple times. For example, if the examples table has three rows of data, the Scenario would run three times.
Examples
Examples is the container table for the place holders in the Scenario.
Notice the path in the example has an <id> placeholder variable. For each run the id would be replaced with the data in the Examples table. Also, notice that we have added Background at the same indentation of Scenario Outline. Background allows us to give context to the scenarios that repeat. The Background can contain one or more steps.
Sample Feature File
The Examples table in this tutorial has one column. We would replace the Mantis Issue id with several ids and check the GET issue call.
## Karate API Tool Demo #Sample Feature - www.TestingDocs.com @Mantis Feature: Get Multiple Issues with Table I want to test Rest API Background: * url 'http://localhost' Scenario Outline: GET multiple Issues Given path '/mantis/api/rest/issues/<id>' And header Authorization = 'DoZSsCCiTFEx8jIm67F4mM7RWh_NLEVd' When method GET Then status 200 Examples: | id | | 1 | | 2 | | 3 | | 4 |
Sample Output
Run report of the Feature.
Karate Automation Tutorials
Karate tool tutorials on this website can be found at:
More information on the tool: