1

Here is a simple example:

 Scenario: Table example
    * table dogs
      | name      | age |
      | 'Charlie' | 2   |
      | 'Jack'    | 4   |
      | 'Rock'    | 9   |
    * match dogs == [{name: 'Charlie', age: 2}, {name: 'Jack', age: 4}, {name: 'Rock', age: 9}]

Is it possible to move table to another file, and just import it? If yes, how exactly?

Thanks in advance

Anfisa Li
  • 25
  • 1
  • 4

2 Answers2

1

If you are want to do this during design time, say, import a table from another data source, you can use some design tool CukeTest, which allow you to edit it visually, import data from a *.csv file into a Table or Example of the gherkin file. You can save a Excel data file to *.csv format.

If you want to do it at runtime, then there are a lot of ways to read data and parse it programmatically, typically from *.json file or *.csv file.

Lean Prop
  • 111
  • 6
0

For this use case I recommend using JSON instead of a table and it will import nicely and have the advantage of being editable by most IDE-s etc.

* def dogs = read('dogs.json')
* match dogs == [{name: 'Charlie', age: 2}, {name: 'Jack', age: 4}, {name: 'Rock', age: 9}]

You could do this also:

* call read('dogs.feature')
* match dogs == [{name: 'Charlie', age: 2}, {name: 'Jack', age: 4}, {name: 'Rock', age: 9}]

And in dogs.feature

Feature:
Scenario:
* table dogs
      | name      | age |
      | 'Charlie' | 2   |
      | 'Jack'    | 4   |
      | 'Rock'    | 9   |

EDIT: since some teams insist on Excel (which I don't recommend) refer to this answer also if applicable: https://stackoverflow.com/a/47954946/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248