Skip to main content

gherkin2robotframework

Description

This tool can be used to facilitate the usage of Cucumber feature files in a RobotFramework Test Automation solution. Although RobotFramework supports BDD style test cases, this support is limited to Given/When/Then keywords. Features like datatables and docstrings are not supported in RobotFramework. This tool will 'compile' Gherkin feature files into RobotFramework test cases and scaffolding for step definitions aka User Keywords.

Usage

Example feature

Feature: Examples

  As a tester
  I want to specify feature files and translate it to RobotFramework
  So I can use the best of both worlds

  Background:
    Given some background stuff

  Scenario: Greeter
    Given a greeter
    When greeting the following persons:
      | Name  | Greeting   |
      | Joe   | Hello      |
      | Mary  | Hi, there! |
    Then the wold is a better place

  @tag
  Scenario Outline: Repetitive stuff
    A nice description
    on multiple lines
    Given a thing with "<thingy>"
    When some action
    Then this happened: <stuff>

    @A
    Examples: A
      Documentation for
      example A
      | thingy  | stuff |
      | AAA     | 123   |
      | BBB     | 456   |

    @B
    Examples: B
      Documentation for example B
      | thingy  | stuff |
      | CCC     | 789   |
      | DDD     | 000   |

  @tag
  Scenario Outline: More stuff
    A nice description
    on multiple lines
    Given a thing with "<thingy>"
    When doing action <action>
    Then this happened: <stuff>

    @A
    Examples: A
      Documentation for
      example A
      | thingy  | action | stuff |
      | AAA     | take   | 123   |
      | BBB     | give   | 456   |

First time generation

After creating your feature files you can translate these into RobotFramework test scripts with the following command:

gherkin2robotframework example.feature

Two files will be generated: example.robot containing the test cases and example_step_definitions.robot containing the user keywords implement the steps. For the default english gherkins the Given/When/Then will be stripped from the keyword names.

*** Settings ***
Documentation    As a tester
...      I want to specify feature files and translate it to RobotFramework
...      So I can use the best of both worlds
Resource    ./examples_step_definitions.robot
Metadata    Feature    Examples
Metadata    Generated by    _gherkin2robotframework on 2020-01-31T13:23:34.958405_

*** Test Cases ***
Greeter
    Background
    Given a greeter
    ${DataTable}=    Create List
    FOR    ${Name}    ${Greeting}    IN
    ...    Joe    Hello
    ...    Mary    Hi, there!
        ${entry}=    Create Dictionary    Name=${Name}    Greeting=${Greeting}
        Append To List    ${DataTable}    ${entry}
    END
    When greeting the following persons:    @{DataTable}
    Then the wold is a better place

Repetitive stuff: A
    [Documentation]    Documentation for
    ...    example A
    [Tags]    tag    A
    [Template]    Scenario Outline Repetitive stuff
    AAA    123
    BBB    456

Repetitive stuff: B
    [Documentation]    Documentation for example B
    [Tags]    tag    B
    [Template]    Scenario Outline Repetitive stuff
    CCC    789
    DDD    000


*** Keywords ***
Background
    Given some background stuff

Scenario Outline Repetitive stuff
    [Documentation]    A nice description
    ...    on multiple lines
    [Arguments]    ${thingy}    ${stuff}
    Background
    Given a thing with "${thingy}"
    When some action
    Then this happened: ${stuff}

example_step_definitions.robot

*** Settings ***
Documentation    Generated by    _gherkin2robotframework on 2020-01-31T12:14:13.397524_
Library    Collections

*** Keywords ***
some background stuff
    Fail    Keyword "some background stuff" Not Implemented Yet

a greeter
    Fail    Keyword "a greeter" Not Implemented Yet

greeting the following persons:
    [Arguments]    @{DataTable}
    Fail    Keyword "greeting the following persons:" Not Implemented Yet

the wold is a better place
    Fail    Keyword "the wold is a better place" Not Implemented Yet

a thing with "${thingy}"
    Fail    Keyword "a thing with "${thingy}"" Not Implemented Yet

some action
    Fail    Keyword "some action" Not Implemented Yet

this happened: ${stuff}
    Fail    Keyword "this happened: ${stuff}" Not Implemented Yet

Regeneration

In case your feature file is changed the .robot files needs to be regenerated.

...
    Scenario: Greeter
        Given a greeter
        When greeting the following persons:
          | Name  | Greeting   |
          | Joe   | Hello      |
          | Mary  | Hi, there! |
        Then the wold is a better place
        And the sun will shine                    #  <-- New step
...

The files can be regenerated with the same command:

gherkin2robotframework example.feature

However, only the example.robot file will be generated (overwritten). The step definition will be parsed and missing keywords will be generated to the console.

Processing gherkin: E:\GitHubProjects\gherkin2robotframework\examples\examples.feature

Missing keywords for: E:\GitHubProjects\gherkin2robotframework\examples\examples_step_definitions.robot

the sun will shine
    Fail    Keyword "the sun will shine" Not Implemented Yet

Limitations and considerations

Background support

The Background keyword is generated to implement the background part of the feature file. Each test case will include this keyword. Using [Test setup] will not work for Scenario Outline with Examples. In Cucumber the Background is applied to each example and in RobotFramework the [Test setup] is only applied to the Test case and NOT to each line in the test case with [Test Template].

Language support

#language:xx is supported, but because the gherkin3 dependency is not recently updated on PyPI. Therefore some keywords (and aliases) are not included.

Release files for gherkin2robotframework 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gherkin2robotframework 0.4.2
File Size Uploaded
gherkin2robotframework-0.4.2.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gherkin2robotframework 0.4.2
File Interpreter ABI Platform
gherkin2robotframework-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / gherkin2robotframework-0.4.2.tar.gz

Download URL gherkin2robotframework-0.4.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3369f2cc0c0b115b857b86ff0a00b49fbe65255a7e07d56ecda12bcb2c07735b
BLAKE2b-256 checksum
How to use checksums
17dbbe24bf6a77ae8de55113872827b0a32ef187ce41b141f98d0e661c138358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2024.

Transparency log

Release files / gherkin2robotframework-0.4.2-py3-none-any.whl

Download URL gherkin2robotframework-0.4.2-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c227ffc67a9ad6659da4f14f0caedbf1d4a8b4f1af8eab3a472628c6c23654ba
BLAKE2b-256 checksum
How to use checksums
ce2c4d6ccf9fe295469ae0de5c5a741dcdc9ddd736d4e83da084f48953f1e482
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page