1

How would I syntactically go about using a table in a separate .feature file for multiple Scenario Outlines in multiple .feature files? I'm working on only updating my test data in one place, with all the benefits that ensues.

I currently have a Scenario Outline with a simple Examples table like this:

Given path 'GetIds'
* header Authorization = auth
* request { Id: <Id> }
* method post
* status 200

Examples:
| Id  |
| 'a' |
| 'b' |

Looking at the links in the results of Karate - Possible to put scenario in a loop? seems like where I should be looking, but I can't infer what my Examples.feature file should look like.

Edit: The following Cucumber example seems very clear to me (blatantly stolen from Cucumber: Scenario Outline reusing examples table )

Examples:{'datafile':'resources/testdata.txt'}

but is apparently invalid in Karate.

Edit2: Creating a separate ids.json file and reading it via * def ids = read('ids.json') works. Using it like this:

Feature: Dummy
Background:                                    
* def ids = read('ids.json')

Scenario: GetIds
* print ids
* print ids.id
* match each ids contains { id: #string }

The above will pass given the data from the old Examples table in json format. But I do not get each id output on * print ids.id and I don't see the GetIds scenario executed more than once. I expected it to execute for each object in the json array in ids.json, as described in https://github.com/intuit/karate#data-driven-features

Pebermynte Lars
  • 414
  • 3
  • 14

1 Answers1

1

The thing is you won't be using Scenario Outline or Examples at all. The "Karate Way" of looping over test data as a JSON-array is different in the following way:

Scenario Outline --> a second feature file
Examples         --> a JSON array

So what I would do is this:

* def ids = read('ids.json')
* def result = call read('called.feature') ids

And in called.feature:

@ignore
Feature:

Scenario:
    * print 'id:', id
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I'm not following the file structure. From this example, it looks like there' s a separate ids.json file, a called.feature file and a third unknown file that contains * def ids = read('ids.json') * def result = call read('called.feature') ids. Is that correct? – Pebermynte Lars Sep 26 '18 at 12:04
  • that is correct. you said you wanted the json to be reusable so it goes in a file. `def ids` is your *main* test – Peter Thomas Sep 26 '18 at 13:17
  • Confirmed. The intention was indeed a separate json file, but only as an addition to the already existing feature file that used to contain the Scenario Outline. It looks like the scenario now has been farmed out to a third feature file, away from the main file. I would prefer to keep the main feature file and the "call read('called.feature') ids" file as one. I'll try to elaborate further in the original question. – Pebermynte Lars Sep 26 '18 at 13:59
  • @PebermynteLars and karate does not support that form. I request you to think over why you "prefer" it one way. I see nothing wrong with it - actually you can re-use the "farmed out" scenario in multiple other scenarios. I have nothing more to say here. if it bothers you so much please submit a PR, this is open source after all. – Peter Thomas Sep 26 '18 at 14:03
  • Because executing the tests in a separate feature file like * def result = call read('test.feature') ids strips the performance numbers in the reports that we have come to rely on. We like that we can use the same tool for DDT and detailed performance data. – Pebermynte Lars Sep 26 '18 at 15:06
  • @PebermynteLars can you do me a favor and run 0.9.0.RC3 in your dev environment and see if the report timings show as you expect. please do submit a feature request - but I personally don't consider this as a priority at all. karate is not a perf test tool. look at the gatling integration. – Peter Thomas Sep 26 '18 at 15:15
  • I would need confirmation that this change to executing feature files would work with parallel execution, first. – Pebermynte Lars Sep 26 '18 at 15:44
  • 1
    @PebermynteLars - hi there - can you look at this feature request and see if you like the sound of it ? https://github.com/intuit/karate/issues/554 – Peter Thomas Oct 09 '18 at 12:36
  • 1
    I think it is both a graceful and clever solution. And it's very clear what happens from the syntax. The points about nested objects also seems very natural. – Pebermynte Lars Oct 11 '18 at 08:14