Open aik099 opened 10 years ago
In fact my solution isn't that good if we think again about a problem. Within Mink
class instance a sessions can appear/disappear/start/stop at will and fact that session has same name as one we remember doesn't prove that it's the same session at all.
The PageFactory::setSession
method, introduced in qa-tools/qa-tools#105, can be used to do a hot swap of session used by page factory. This however won't replace session within Pages/Elements that you have created before.
The PageFactory is created only once (when extension is initialized - https://github.com/qa-tools/behat-extension/blob/master/src/QATools/BehatExtension/QATools.php#L78) and therefore it uses Mink's session available at the moment.
Such setup however is can backfire when multiple sessions are configured in
MinkExtension
. TheMinkExtension
works like this:To solve this we need to have separate page factory instance created per session and call
->getPageFactory()
(instead of->pageFactory
) that will:->pageFactories
array (key is Mink's session name, value is page factory created for it)Thanks to caching in
->pageFactories
array we don't need to create new page factory for each scenario.