Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run gherkin style test cases in Robot Framework

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.

like image 766
RayCh Avatar asked Jan 21 '14 14:01

RayCh


People also ask

How do you write test cases in Gherkin format?

To create Gherkin test scenarios suitable for both manual and automated execution, turn on the Automation ready (BDD mode) setting of your test project. This will command the test editor interpret the Gherkin keywords appropriately and automatically create action words (reusable steps) from them.

How do you run test cases in Robot Framework?

Executing Your Selenium Tests in the Robot Framework To execute robot tests in your prompt, type: robot path/to/tests. 'path/to/tests' should be a name of a suite file or a suite directory.

What is Gherkin Robot Framework?

Robot Framework is a Test driven development framework. You can utilize it by a keyword driven approach or a more BDD approach using a Gherkin style test.


1 Answers

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.

like image 101
Harri Avatar answered Oct 07 '22 06:10

Harri