-
Notifications
You must be signed in to change notification settings - Fork 280
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
Allow accessing selectors handler in Session #602
Comments
Also a strange thing is that Session internally creates ElementFinder that immediately goes to the DocumentElement that is created and then never uses ElementFinder at all. What I'm saying here is that Session needs Driver and DocumentElement to operate, but not Driver and ElementFinder that give to it. |
Within Behat, you should use an extension to register more selectors in the selectors handler IMO.
The difference is that the ElementFinder is a service which can be defined externally to be configured. On the other hand, it does not reallyt make sense for a Session to receive a DocumentElement created externally IMO |
Is there any example on how to do it? |
Within my library I've creates sub-class from Problem that I'll face if I want to upgrade to Mink 2.0 is that |
@aik099 why using inheritance on the NodeElement ? It may be better to build your own API by composition, by wrapping the NodeElement in your own class |
If I wrap it, then to provide access to all NodeElement methods I need to do either:
If I go 1st way, then I might get overhead due |
third solution: give access to the underlying NodeElement Btw, your current API is already weird: you redefine |
Because it makes sense to wait in seconds, rather then milliseconds. I haven't seen any potential usage for such small waiting timeouts (except for in JavaScript), so I raised it to seconds (from milliseconds). Also it makes more sense to specify 0.5sec instead of 500ms to me. |
That will complicate things when dealing with |
Also WebElement, that extends NodeElement perfectly represents similary named class in Selenium itself. There WebElement is interface which is implemented by anything that can be found by Selenium. |
yeah, but some code expecting a NodeElement would then be unable to use your own NodeElement, becaus eof a different meaning for the argument it passes. Your WebElement breaks the OOP rule (child classes should be usable in all places expecting the parent class)
|
And it is usable. Child class also is able to change the way how methods of parent class work and that's normal. Say we have If I keep milliseconds, then it would create inconsistency in other library parts, where waiting is done is seconds. I originally created
It does so already for some common methods, but having shortcuts for all methods just doesn't make sense considering whole So I already use the composition idea you've proposed within the |
you are not changing how it works. you are changing the API. And this is not normal
I was suggesting to proxy |
How to detect what's being changed? To me public API is names/types of method and it's arguments and return value type. That is kept the same. What method does internally isn't relevant, isn't it?
I understood that already, but it will look like hell from TypifiedElement perspective: |
The public API says that the duration is an integer representing milliseconds. You are now sayign it is seconds. So any code written against the Mink API will wait 1000 times longer when receiving your own object |
Ok, so I ask 3rd time: how about changing it to seconds also in Mink (in |
If you agree, then I've already created PR for that: #603 |
@aik099 coming back to the original topic, what is the actual use case for accessing the SelectorsHandler from the Session in 2.0 ? |
Now with #603 PR merged and Here are the use cases:
I wonder how Behat is able to inject new selectors in existing SelectorsHandler even before it goes into Session. Maybe with current API where SelectorsHandler is injected into Session this isn't a problem. |
method is gone in 2.0 (the Escaper class of 1.6+ should be used, or nothing at all for the named selector as it now escapes the locator properly)
Can you link to the place in QATools doing this registration ?
hmm, the need to convert selectors to XPath separately from the Mink element finding is indeed a case where it would be needed to access it. Is your WebElement class expected to be instantiated by the user or could it be done from a place knowing the SelectorsHandler separately from the session ? For find methods, you don't need the selectors handler (the find method is using it internally).
Behat relies on dependency injecting (using the Symfony component). To register your own selector, you would define it as a service in a Behat extension and tag it appropriately so that it is found by MinkExtension: https://github.com/Behat/MinkExtension/blob/2ab8c00c59995824c6ebcd50617f8c3a4d78d2d9/src/Behat/MinkExtension/ServiceContainer/MinkExtension.php#L286 |
Now is since when exactly, the Mink 1.6 release? I though that auto-escaping in NamedSelector was only done in 2.0 version.
https://github.com/qa-tools/qa-tools/blob/develop/library/QATools/QATools/PageObject/PageFactory.php#L192-L194 - the method
Usually it's instantiated automatically, but all element classes (including typified ones, which wrap around WebElements) can be instantiated manually and I don't want to make it harder for user to do it because of additional dependencies in constructor. Since in Mink 1.6 you can create
I'm not using |
No, |
I've created qa-tools/qa-tools#168 to use composition in WebElement. Not sure if I'll end up in creating BC break in QA-Tools by doing so. |
In the 1.x versions it was possible to use
Session::getSelectorsHandler()
method to get selectors handler and change it (e.g. add new selectors to it).In the
2-architecture-changes
branch things have changed considerably and now we have (see https://github.com/Behat/Mink/blob/2-architecture-changes/src/Behat/Mink/Session.php#L46):As you can see the SelectorsHandler is now created deep within ElementFinder and ElementFinder itself is created within Session.
If developer has full control over Session creation then of course he can create ElementFinder as he see fits and in the process obtain reference to SelectorsHandler.
However within Behat developer gets already created session via
->getSession()
method that he can't change anymore.The text was updated successfully, but these errors were encountered: