让我看看能否告诉你我有多困惑。
如果我只使用带内联变量的生菜特征文件,一切正常。例如,如果我创建以下要素文件:
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文件夹中并将“断言False”更改为“断言True”以使测试通过,我会以漂亮的颜色传递:< / p>
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)
现在,我想在mix中添加一个Examples表。我所做的只是添加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这个例子显示“情景大纲:因子[0-4]”,这很奇怪,因为我不知道是否需要[0-4]。在我的测试中它似乎没有任何区别,尽管我没有任何成功的测试,所以我可能完全错了。
我需要做的是弄清楚为什么生菜看不到那些内联“<placeholder>
”语法的步骤。
有人可以为我阐明这个吗?
答案 0 :(得分:3)
我看到了这个页面: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]”不是必需的,使用示例时,请确保使用“场景大纲”而不是“场景”。