是否可以使用cucumber场景作为函数?
比如:是否可以使用cucumber场景作为函数?,cucumber,capybara,factory-bot,Cucumber,Capybara,Factory Bot,比如: Scenario: Create a Test Category Given I am on the regression test test cases page When I follow "New Category" And I fill in "Name" with "Test Category" And I press "Add Category" Then I should see "Test Category" within ".test-categor
Scenario: Create a Test Category
Given I am on the regression test test cases page
When I follow "New Category"
And I fill in "Name" with "Test Category"
And I press "Add Category"
Then I should see "Test Category" within ".test-categories-list"
Scenario: Add a Test Case
Given I "Create a Test Category"
我想要一个逐步的过程,创建一个测试类别,然后创建一个测试用例。如果不做一个给定的测试,我创建了一个测试类别,然后在它上做了一个工厂,这是可能的吗 在这种情况下,您应该像对待生产代码一样对待测试代码,并将其封装在类中。 然后,您可以在任何需要的地方轻松地重用它 为了便于说明:
class TestCategory
def create(values)
follow_new_category
fill_in_name
press_add
end
def follow_new_category
end
def fill_in_name
end
def press_add
end
end
然后,您可以通过以下步骤调用这些方法:
When /I fill in "Name" with "(.*)"/ do |category_name|
TestCategory.new.fill_in_name(category_name)
end
您可能希望以其他方式管理TestCategory类的生命周期,而不是每次都实例化一个新的生命周期
然而,你的步骤是非常必要的,这被认为是不好的做法。如果它这样说会更好:
Scenario: Create a Test Category
Given I am on the regression test test cases page
When I add a test category
Then I should see "Test Category" within ".test-categories-list"
那么你就不需要把你的支持代码分解成这么多小的方法了。那么你如何在cucumber中的TestCategory类中调用创建方法呢?我可以做一些类似于给定场景的事情吗:创建一个测试类别已经运行了吗?不,你不能。场景是独立的。如果你想要重用,你应该在你的代码和/或步骤定义中进行构建。你可以做的是假设已经创建了一个测试类别,并以我在回答中描述的相同方式重用代码