I had this problem Cucumber scenarios for extremely long work flow
And now I've been writing isolated scenarios for each of a long series of multi-part form steps. I have a Background
section that sets up each Scenario
. But now when I run the entire feature, cucumber wants to repeat the Background
for each Scenario
. I want to test a Scenario
that builds off of all the previous ones.
Here is the bare outline of what my feature looks like:
Feature: Submit a manuscript
In order to complete a manuscript submission
As a corresponding author
I want to complete the to-do list
Background:
Given I am logged in as "Steve"
And an article_submission "Testing Web Apps" exists
And "Steve" is a "Corresponding Author" for "Testing Web Apps"
And I am on the manuscript to-do list page for "Testing Web Apps"
Scenario: Steve suggests reviewers for his manuscript
...
Scenario: Steve completes the manuscript fees to-do item
...
Scenario: Steve wants to add Barbara as a co-author
...
Scenario: Steve uploads necessary files
...
Scenario: Steve edits the fees page and general information page
...
Scenario: Steve re-uploads the manuscript file
...
Scenario: Steve completes the Copyright Transfer
...
Scenario: Steve completes Author Responsibilities & Agreement
...
# These scenarios depend on all the previous ones having run
Scenario: Steve Completes submission
...
Scenario: Steve goes back and make changes
...
Scenario: Steve fills out payment page
Is there are way to require previous scenarios to be run? And is there a way of running the Background
only once?
Background in Cucumber is used to define a step or series of steps that are common to all the tests in the feature file. It allows you to add some context to the scenarios for a feature where it is defined. A Background is much like a scenario containing a number of steps.
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered. After hooks will be run after the last step of each scenario, even when there are failing, undefined, pending or skipped steps. Background. Background is used to set up a precondition.
Scenario outline is exactly similar to the scenario structure, but the only difference is the provision of multiple inputs. In order to use scenario outlines, we do not need any smart idea, we just need to copy the same steps and re-execute the code.
Unfortunately, this is not possible.
I decided to "freeze" the application in the state it was immediately after running the Feature. I did this by adding hooks that dump and load the databse.
In features/support/hooks.rb
I have:
After('@complete-submission') do
# Dump the database
exec "mysqldump -u root --password=### onc_test > #{Rails.root}/support/submission.sql"
end
Before('@load-submission') do
# Load the database
exec "mysql -u root --password=### onc_test < #{Rails.root}/support/submission.sql"
end
This is working basically, except the @load-submission
fails mysteriously to run the Scenario, but the database is loaded. So I have to run it again without the tag. Maybe someone can help me figure that own out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With