2

How can I implement Gherkin data tables in Robot Framework?

The following snippet should pass two sets of (n, is_prime) parameters to Keywords in order to verify that:

is_prime(5) = True

is_prime(6) = False

*** Test Cases ***
Function should verify prime number
    Given I have a positive integer and is_prime() function
        | n | is_prime |
        | 5 | True     |
        | 6 | False    |
    When I check whether n is prime
    Then is_prime() should verify this

Note: This is not about Scenario Outline. I found https://gist.github.com/Tset-Noitamotua/8f06bd490918a56b0485630016aef60b and can write Robot test using Examples table.

Here is a Python function, which I use for checking prime number:

import math


def is_prime(num):
        if num < 2:
            return False
        sqr = int(math.floor(math.sqrt(num)))
        for i in range(2, sqr + 1):
            if num % i == 0:
                return False
        return True
taggore
  • 33
  • 1
  • 5
  • Simply using the [test template feature](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-templates) of RF is not enough? Without this scenario thing you have found. – Bence Kaulics Feb 01 '19 at 11:11
  • @BenceKaulics, I need to see a working example in the context of Gherkin data table. All other parameterizing snippets I can find refer to non-Gherkin RF syntax. Since only that particular Scenario Outline example exists, data tables might be not supported. – taggore Feb 01 '19 at 11:57

1 Answers1

6

In short: Multi-line gherkin is not supported when using Test Template feature.

In Robot Framework Gherkin are Robot Framework keywords within the context of a single Test Case. A Test Template Feature only supports a single keyword. So either you create a single line keyword from your multi-line Gherkin or accept that the combination isn't possible.

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43