使用 cucumber ruby 将一个特征文件作为背景步骤调用到另一个特征文件
Calling one feature file as background step into another using cucumber ruby
我有一个包含 8-9 行步骤的功能文件 A,它涵盖了一个场景。现在我需要将特征文件 A 用作特征文件 B 中的背景步骤,方法是将步骤数减少到 3-4。
我的做法:
- 在功能文件 B 中 - 将步骤(从功能文件 A)减少到 3-4 行,使用辅助方法并添加为后台步骤。
特征文件A:
Feature: I want to create an event
Background: User is Logged In
Given a logged in user
Scenario: Creating an event
Given I select event
And I add event details
And I add start and end time
Then Timings will be added successfully
When I add ticket information and continue
And Publish my event
Then I verify event will be created successfully
特征文件 B
Feature: Place an order
Background: Event is created
Given a logged in user
When I select event and fill in required details
Then event should be published
我担心重复。我通过减少步骤数将功能文件 A 用作功能文件 B 中的后台步骤,但在功能上两个功能文件都在测试相同的功能。
如果可能,请提出更好的方法。谢谢
因此,只有在压缩步骤也能正确传达信息的情况下,您才应该从根本上使用辅助方法来减少步骤数。所以这是一个例子(你在这里也不需要助手),那将是一个很好的用例。
Given I have a party of 2/1/0 # This means adults/children/infants
And the child is under 12
And I am flexible on my flights
And I am going to Spain
When I search for flights
Given I have Spanish flights displayed # You could also add the pax in here if you wanted
现在,如果您想使用辅助方法,那也很好,但您需要记住,Cucumber 主要是一种用于鼓励协作以及在同一位置提供文档、测试和规范的工具。因此,一旦您尝试擦干台词,请考虑一下您是否真的只是想“压缩”台词。
即
Given('I am {int} years old') do |age|
@person.age = age
end
Given('my name is {word}') |name|
@person.name = name
end
Given('my hometown is {string}') |hometown|
@person.location = hometown
end
可以成为
Given('I am {word}, {int} years old from {string}') |name, age, hometown|
@person.name = name
@person.age = age
@person.location = hometown
end
希望其中一些技巧能给您带来一些思考。
我有一个包含 8-9 行步骤的功能文件 A,它涵盖了一个场景。现在我需要将特征文件 A 用作特征文件 B 中的背景步骤,方法是将步骤数减少到 3-4。
我的做法:
- 在功能文件 B 中 - 将步骤(从功能文件 A)减少到 3-4 行,使用辅助方法并添加为后台步骤。
特征文件A:
Feature: I want to create an event
Background: User is Logged In
Given a logged in user
Scenario: Creating an event
Given I select event
And I add event details
And I add start and end time
Then Timings will be added successfully
When I add ticket information and continue
And Publish my event
Then I verify event will be created successfully
特征文件 B
Feature: Place an order
Background: Event is created
Given a logged in user
When I select event and fill in required details
Then event should be published
我担心重复。我通过减少步骤数将功能文件 A 用作功能文件 B 中的后台步骤,但在功能上两个功能文件都在测试相同的功能。
如果可能,请提出更好的方法。谢谢
因此,只有在压缩步骤也能正确传达信息的情况下,您才应该从根本上使用辅助方法来减少步骤数。所以这是一个例子(你在这里也不需要助手),那将是一个很好的用例。
Given I have a party of 2/1/0 # This means adults/children/infants
And the child is under 12
And I am flexible on my flights
And I am going to Spain
When I search for flights
Given I have Spanish flights displayed # You could also add the pax in here if you wanted
现在,如果您想使用辅助方法,那也很好,但您需要记住,Cucumber 主要是一种用于鼓励协作以及在同一位置提供文档、测试和规范的工具。因此,一旦您尝试擦干台词,请考虑一下您是否真的只是想“压缩”台词。
即
Given('I am {int} years old') do |age|
@person.age = age
end
Given('my name is {word}') |name|
@person.name = name
end
Given('my hometown is {string}') |hometown|
@person.location = hometown
end
可以成为
Given('I am {word}, {int} years old from {string}') |name, age, hometown|
@person.name = name
@person.age = age
@person.location = hometown
end
希望其中一些技巧能给您带来一些思考。