Home > Back-end >  Calling other feature and reading data from csv not in examples
Calling other feature and reading data from csv not in examples

Time:11-18

I am usually calling other feature and reading data from csv in the examples, like below.

Scenario Outline: 
* call read('classpath:controller/Controller.feature')

Examples:
|read('classpath:com/testdata/Test.csv')|

This time I still want to read data from csv, but use Examples for other purpose, like below. Is it possible to read data from csv still? Maybe passing as parameter?

Scenario Outline: 
        * call read('classpath:controller/Controller.feature'){read('classpath:com/testdata/Test.csv')}
    
    Examples:
    |gain |spend    |
    |12000| 12008   |
    |3400 | 4655    |

I know it works this way but I have to pass index [0], and if I have more test data in csv it won't work

Scenario Outline: 
    * def testData = read('classpath:com/testdata/Test.csv')
    * call read('classpath:controller/Controller.feature'){ "name": "#(testData[0].name)", "age": "#(testData[0].age)"}

Examples:
|gain |spend    |
|12000| 12008   |
|3400 | 4655    |

CodePudding user response:

I'll just give one tip. When you use Examples the row index is available as a variable called __num: https://github.com/karatelabs/karate#scenario-outline-enhancements

So you can do things like this:

Feature:

Scenario Outline:
* def data = [{ id: 0 }, { id: 1 }]
* match (data[__num].id) == temp

Examples:
| temp! |
| 0     |
| 1     |
  • Related