Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tag options to preserve sessions between scenarios #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/Behat/MinkExtension/Listener/SessionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ public static function getSubscribedEvents()
}

/**
* Configures default Mink session before each scenario.
* Configuration is based on provided scenario tags:
* Configures Mink sessions before each scenario.
*
* `@javascript` tagged scenarios will get `javascript_session` as default session
* `@mink:CUSTOM_NAME tagged scenarios will get `CUSTOM_NAME` as default session
* Other scenarios get `default_session` as default session
* Configuration is based on provided scenario tags.
*
* `@insulated` tag will cause Mink to stop current sessions before scenario
* instead of just soft-resetting them
* Default session:
* `@javascript` tagged scenarios will get `javascript_session` as default session
* `@mink:CUSTOM_NAME` tagged scenarios will get `CUSTOM_NAME` as default session
* Other scenarios get `default_session` as default session
*
* Scenarios sessions isolation:
* By default, sessions get soft-resetted before each scenario
* `@insulated` tag will cause Mink to stop current sessions before scenario instead of just soft-resetting them.
* `@resetSessions` tag will explicitly cause Mink to soft-reset current sessions before scenario.
* `@preserveSessions` tag will keep current sessions opened. If set at the feature level you can use the other
* tags (`@insulated` or `@resetSessions`) to specify at which scenario Mink should start a new session.
*
* @param ScenarioLikeTested $event
*
Expand All @@ -101,7 +107,12 @@ public function prepareDefaultMinkSession(ScenarioLikeTested $event)
if ($scenario->hasTag('insulated') || $feature->hasTag('insulated')) {
$this->mink->stopSessions();
} else {
$this->mink->resetSessions();
$preserveSessions = $scenario->hasTag('preserveSessions') || $feature->hasTag('preserveSessions');
$preserveSessions = $preserveSessions && !$scenario->hasTag('resetSessions');

if (!$preserveSessions) {
$this->mink->resetSessions();
}
}

$this->mink->setDefaultSessionName($session);
Expand Down