How to run gherkin style test cases in Robot Framework

RayCh picture RayCh · Jan 21, 2014 · Viewed 18.6k times · Source

Is there some configuration setting that I must perform to get Robot Framework (RF) to run Gherkin/BDD style test cases?

I have installed RF 2.8.3 on Windows 7 and is running OK with Selenium2Library and DatabaseLibrary. According to the user docs and other info on the web, I should be able to write and run Gherkin style tests. However, when I do this, I get errors. RF does not strip the Gherkin keywords (Given, When, Then, ...) before trying to match the keyword:

Tests.Group001 GeneralTests
==============================================================================
Scenario: No template operation selected                              | FAIL |
No keyword with name 'But page does not contain a no template operation selected error message' found.
------------------------------------------------------------------------------

I run the tests using a straight-forward:

pybot ../Tests

My sample test file is:

*** settings ***

Library     Selenium2Library
Library     DatabaseLibrary
Library     kw_common

*** Test Cases ***

Scenario: No template operation selected
    Given I have logged in and I have selected to perform template configuration
    When I do not select a template operation
    But page does not contain a no template operation selected error message
    And I press the next button
    Then I should not see a template operation selected error message


*** Keywords ***

I have logged in and I have selected to perform template configuration
    Log     Given I have logged in and I have selected to perform template configuration

I do not select a template operation
    Log     No template operation selected

page does not contain a no template operation selected error message
    Page Should Not Contain     'ddTemplateOperation' is required.

I press the next button
    Click Element               xpath=//input[contains(@id,'next')]

I should not see a template operation selected error message
    Page Should Contain     'ddTemplateOperation' is required.

Help would be much appreciated. Thanks.

Answer

Harri picture Harri · Jan 22, 2014

From the official documentation http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#ignoring-given-when-then-and-but-prefixes :

Prefixes Given, When, Then and And are dropped when matching keywords are searched

So page does not contain a no template operation selected error message keyword needs to be renamed to But page does not contain a no template operation selected error message.