如何在Robot Framework中运行小黄瓜样式测试用例

时间:2014-01-21 14:29:19

标签: robotframework gherkin

我是否必须执行一些配置设置才能让Robot Framework(RF)运行Gherkin / BDD样式测试用例?

我已在Windows 7上安装了RF 2.8.3,并且正在使用Selenium2Library和DatabaseLibrary运行正常。根据用户文档和网络上的其他信息,我应该能够编写和运行Gherkin样式测试。但是,当我这样做时,我会收到错误。在尝试匹配关键字:

之前,RF不会剥离Gherkin关键字(Given,When,Then,...)
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.
------------------------------------------------------------------------------

我使用直接的方式运行测试:

pybot ../Tests

我的示例测试文件是:

*** 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.

非常感谢帮助。感谢。

1 个答案:

答案 0 :(得分:3)

来自官方文档http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#ignoring-given-when-then-and-but-prefixes

  

在匹配关键字时删除Prefixes Given,When,Then和And   被搜查

因此page does not contain a no template operation selected error message关键字需要重命名为But page does not contain a no template operation selected error message