Search code examples
cucumberkarategherkin

Passing range of number like 0 -100 in an example section of cucumber feature file


I am trying to pass the range of number in index from 0 - 100 or if I have n number then 0 to n. how do I do that ? Could you please help me with the sample code in cucumber / karate ?

Examples:
  | index | number | em_number |
  | 0     | 1      |   10          |
  | 1     | 1      |   10          |
  | 2     | 1      |   10          |
  | 3     | 1      |   10          |
  | 4     | 1      |   10          |

Solution

  • I think you need to spend some time on fundamentals before trying to over-complicate your tests.

    That said, karate has a built-in function. Try this:

    * def nums = karate.range(5, 9)
    * match nums == [5, 6, 7, 8, 9]
    

    And then please read the docs on JSON transforms: https://github.com/karatelabs/karate#json-transforms