Cucumber 黄瓜重用示例
我想在使用以下信息行注册时使用下面代码中的示例,而不必指定每个参数,也不必重复示例中的表格 这可能吗Cucumber 黄瓜重用示例,cucumber,Cucumber,我想在使用以下信息行注册时使用下面代码中的示例,而不必指定每个参数,也不必重复示例中的表格 这可能吗 Scenario Outline: signing up a user that already exists Given I am registered as "<username>" with password "<password>" When I sign up with the following information Then I s
Scenario Outline: signing up a user that already exists
Given I am registered as "<username>" with password "<password>"
When I sign up with the following information
Then I should be on the sign up page
And I should see "user already registered"
Examples:
| email | username | name | password | password_confirmation | city | mobile_numbers |
| foo@bar.com | existent | some user | temp123 | temp123 | foobar | 70 707070 |
生成cucumber项目文件夹时,该结构将在features文件夹内的support目录中包含一个名为env.rb的ruby文件以及step_definitions文件夹。在这里,您可以定义方法、变量等,它们将作为同一项目中所有其他测试的公共源 因为Cucumber是Ruby宝石,所以数据是以Ruby的格式定义的。您可以将它们定义为方法或变量。我更喜欢在ruby中将它们定义为方法,方法返回它们的最后一行。所以你的方法看起来像
def email
"foo@bar.com" # returns this when email is called
end
def username
"existent"
end
等等
您可以优化它以满足您的需要。您将在ste_定义文件中调用它们,就像调用任何普通ruby函数一样。我可能没有很好地解释自己。。。我想重复使用下表中的示例:在我使用以下信息注册时的行中。我想看看这是否可能,而不必做类似的事情:当我使用以下信息注册时:,,…在这种情况下,您需要在env.rb中的Ruby中创建一个方法,该方法将包含所有这些值,并且您将在step_定义文件中调用该函数。所以它将类似于def login-在这里创建变量-现在执行操作结束,您可以调用login方法,它将为您完成所有操作。GitHub中的示例项目有一个非常基本的例子。很抱歉,我无法格式化注释中的代码