I have done a lot of R&D on this but I am unable to find a solution.
I need to maintain a login session between different scenarios in a single feature file.
I have made a function I am logged in
and I have written in background. so at the start of every scenario the login happens. but what I want is to maintain a single login session across the scenarios.
Can anyone suggest?
example Code is:
Feature: To test the output
Background:
Given I am logged in
@javascript
Scenario: To test the positive input
When I fill in "test" with "aab"
And I press "add"
Then I should see "welcome"
@javascript
Scenario:To test the negative inputs
When I fill in "test" with "@#$@!!111"
And I press "add"
Then I should see "Sorry,invalid input please try again"
Now if another person reviews my code he would come to know about the positive and negative test cases. but every time the scenarios are reloaded, what if I have 50 scenarios in a feature. for bigger projects. it doesn't look good at every scenario I log in and I waste extra 15 minutes in total. what I want is after every scenario in a single feature file, the test continues with the same login session.
It can't be done. Behat scenarios are independent on purpose. Otherwise, you would risk state leaking from one scenario to another.
You're not approaching the problem from the right direction. Sacrificing scenario separation for speed improvements will hurt you in the long run.
Assuming that logging in is tested as one of the features, in other scenario where logging in is required, you don't have to be using the actual login form. Think of doing it programaticaly.
Also, you seem to be using Behat for functional testing, while it's build for verifying business expectations. You could consider using Mink directly, which would give you more power.