In a feature file have a Background and several Scenarios, but now need a Scenario related to same feature that don't have to run background logic, is possible to disable for only a scenario?
UPDATE - Add Example:
Feature: Sign Up
In order to access to protected parts of site
A user
Should sign up
Background:
Given I am on sign up page
And I am not logged in
Scenario: User sign up succesfully
When I sign up with valid fields
Then I should view dashboard page
Scenario: User altredy sign up
When I sign up with altredy registred user e-mail
Then I should view altredy sign up message and link to forgot password page
Scenario: User try to sign up with missing/wrong data
When I will try to sign up with missing/wrong data
Then I should error message
Scenario: User altredy sign in
#here disable background
Given I am logged in
When I am on sign up page
Then i should be redirect to dashboard page
There can be only one Background in one Feature file and it allows us to set a precondition for all Scenarios in a Feature file. A Background is like a Scenario, containing a number of Steps. Background is run before each Scenario, but after the BeforeScenario Hooks.
If you want your background to be run only once. You can add condition with an instance variable ex, i==0 then execute the logic and increment i at the end of the method. For the next scenario, i value is 1 which is not equal to 0,the it won't execute the logic.
The Background keyword is applied to replicate the same steps before all Scenarios within a Feature File. It should be used for defining simple steps unless we are forced to bring the application to a state which requires complicated steps to be carried out. As requested by the stakeholders of the project.
Using Background in CUCUMBER, we can make the feature file more readable and less complex in lieu of writing steps over and over again for each scenario. When we execute the feature, at run time, the steps in Background are executed in the beginning of each scenario.
You could put that only Scenario in other Feature file where there's no background or it has it's own background
Remove the background from the feature file and then put its logic on the step definitions, something like
Given 'I am on sign up page' do
some code here
end
Given 'I am not logged in' do
some code here
end
then on each first step
Given 'I sign up with valid fields' do
step 'I am on sign up page'
step 'I am not logged in'
the rest of your code for this step
end
Given 'I sign up with altredy registred user e-mail' do
step 'I am on sign up page'
step 'I am not logged in'
the rest of your code for this step
end
Given 'I will try to sign up with missing/wrong data' do
step 'I am on sign up page'
step 'I am not logged in'
the rest of your code for this step
end
This is not pretty though you would repeat those at least 3 times.
You could get rid of that Scenario and paste it's steps in the first Scenario, something like
Scenario: User sign up succesfully
When I sign up with valid fields
Then I should view dashboard page #this is your Given I am logged in step
When I am on sign up page
Then i should be redirect to dashboard page
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