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

Stale Mink's Session usage in PageFactory #11

Open
aik099 opened this issue Aug 30, 2014 · 2 comments
Open

Stale Mink's Session usage in PageFactory #11

aik099 opened this issue Aug 30, 2014 · 2 comments
Labels

Comments

@aik099
Copy link
Member

aik099 commented Aug 30, 2014

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. The MinkExtension works like this:

  1. it analyzes scenarios and figures out which sessions needs to be created for them
  2. for example in most simple case there will be 2:
    • one using GoutteDriver for simple pages
    • one using Selenium for pages that require JavaScript interactions
  3. in before scenario hook the name of Mink's default session is set to one, that needs to be used by the scenario

To solve this we need to have separate page factory instance created per session and call ->getPageFactory() (instead of ->pageFactory) that will:

  1. look in ->pageFactories array (key is Mink's session name, value is page factory created for it)
  2. if no page factory found for that session name, then create and return it
  3. if page factory found then return it

Thanks to caching in ->pageFactories array we don't need to create new page factory for each scenario.

@aik099 aik099 added the bug label Aug 30, 2014
@aik099
Copy link
Member Author

aik099 commented Sep 5, 2014

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.

@aik099
Copy link
Member Author

aik099 commented Sep 7, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant