1

让我看看我能不能告诉你我有多困惑。

如果我只使用内联变量的生菜特征文件,那么一切正常。例如,如果我创建以下功能文件:

Feature: File Finder
    I need to just look for the presence of certain files on a system

Scenario Outline:  Verify the presence (or absence) of a file on a system
    Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
    Then I can look for "/var/log/nginx.log" and know that it should "not" be there

并针对它运行生菜,它告诉我创建以下步骤:

You can implement step definitions for undefined steps with these snippets:

# -*- coding: utf-8 -*-
from lettuce import step

@step(u'Given I log into a system at "([^"]*)" as user "([^"]*)" with password "([^"]*)"')
def given_i_log_into_a_system_at_group1_as_user_group2_with_password_group2(step, group1, group2, group3):
    assert False, 'This step must be implemented'
@step(u'Then I can look for "([^"]*)" and know that it should "([^"]*)" be there')
def then_i_can_look_for_group1_and_know_that_it_should_group2_be_there(step, group1, group2):
    assert False, 'This step must be implemented'

如果我将该标题(“从生菜导入步骤”)和这些步骤粘贴到 filefinder.py 文件夹中,并将“assert False”更改为“assert True”以使测试通过,我将顺利通过:

Feature: File Finder
  I need to just look for the presence of certain files on a system

Scenario: Verify the presence (or absence) of a file on a system
  Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
  Then I can look for "/var/log/nginx.log" and know that it should "not" be there

1 feature (1 passed)
1 scenario (1 passed)
2 steps (2 passed)

现在,我想添加一个示例表。我所做的只是添加Then I can ask <manager> for <item>作为我的第三步和以下示例表:

Examples:
    | manager   | item            |
    | "bob"     | "raise"         |
    | "suzy"    | "more switches" |
    | "bill"    | "more coffee"   |

当我对此运行生菜时,它告诉我:

You can implement step definitions for undefined steps with these snippets:

# -*- coding: utf-8 -*-
from lettuce import step

@step(u'Then I can ask <manager> for <item>')
def then_i_can_ask_manager_for_item(step):
    assert False, 'This step must be implemented'

所以,我将它添加到我的 filefinder.py 文件中,并将“assert False”更改为“assert True”,只是为了让它通过并在我的控制台上看到绿色。如果我对此运行生菜,它会给我完全相同的响应,就好像它无法识别占位符<manager><item>创建一个有效的步骤一样,我猜。这是我唯一一次无法创建它要求的步骤 - 当我使用此处描述的占位符时:http: //lettuce.it/tutorial/scenario-outlines.html 奇怪的是示例显示“场景大纲: Factorials [0-4]" 因为我不知道是否需要 [0-4]。尽管我没有任何成功的示例测试,但在我的测试中似乎没有任何区别,所以我可能完全错了。

我需要做的是弄清楚为什么生菜看不到那些具有“ <placeholder>”语法内联的步骤。

有人可以为我解释一下吗?

4

1 回答 1

4

我遇到了这个页面: http: //lettuce.it/intro/wtf.html恰当地命名为 wtf!

我需要做的是<placeholders>在示例表中加上引号并删除引号。

现在,我的功能文件如下所示:

Feature: File Finder
    I need to just look for the presence of certain files on a system

Scenario Outline:  Verify the presence of a file on a system [0-3]
    Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
    Then I can look for "/var/log/nginx.log" and know that it should "not" be there
    Then I can ask "<manager>" for "<item>"

Examples:
    | manager | item          |
    | bob     | raise         |       
    | suzy    | more switches |
    | bill    | more coffee   |

它在我的控制台上以各种绿色传递:

Feature: File Finder
  I need to just look for the presence of certain files on a system

Scenario Outline: Verify the presence of a file on a system
  Given I log into a system at "172.16.100.23" as user "cadmin" with password "cadmin"
  Then I can look for "/var/log/nginx.log" and know that it should "not" be there
  Then I can ask "<manager>" for "<item>"

Examples:
  | manager | item          |
  | bob     | raise         |
  | suzy    | more switches |
  | bill    | more coffee   |

1 feature (1 passed)
3 scenarios (3 passed)
9 steps (9 passed)

要点...“[0-4]”不是必需的,在使用示例时,请确保使用“场景大纲”而不是“场景”。

于 2013-02-28T20:41:55.740 回答