-
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
Mink element selection improvements #872
Comments
It's not as bad as it seems. There is a documentation page showing all possible selector/locator values: https://mink.behat.org/en/latest/guides/traversing-pages.html#selectors. Architecturally, the idea of having Perhaps, as a BC break, we could modify the signature of the Theoretically, we can adjust PhpStorm auto-complete (via DocBlock or I'm not sure if using these intermediate classes to define a selector+locator combo would result in any overhead. How I use Mink
TODO
Questions
List of the convenience methods (all are powered by the named selector):For anyone using Mink directly (not through the Behat/QA-Tools/etc. library), they might provide a good starting point.
|
@aik099 thanks, glad to see that the idea is well received.
Agreed, but the current approach does require us to keep it in sync with documentation outside of code. I for one wasn't even aware of the documentation you linked to. 😅 In short: it would be nicer to write code that is self-documenting. In this case, stricter types (class/interface instead of strings) would narrow things down.
I think that would be extremely difficult and next to impossible for certain things. The final result would be to say that "when $selector is 'css' then $locator must be a string containing a css selector".. I don't see why we should choose bad design and a tonne of hacks, over some simple classes that would easily do the job.
Pretty sure that would be negligible and not at all a good reason considering the many benefits.
Strictly speaking, good tests should go by well-defined locators e.g. element names and roles instead of e.g. css classnames, so I see why we would want to keep those methods. But I also see how css selectors can work in both cases. I think I would keep them as they are.
In general, I disagree: I see a lot of advantages, actually:
The code I posted was just to give an idea. The names area are not final. The bigger question here is if/how these classes would relate to mink's selector classes.
True, that was the intention. I'll update that.
Yep, as said, just a quick prototype. The exact syntax would depending on which version we decide to target.
I haven't thought too much about it. I guess that for real web browsers, this can always be implemented using the javascript visibility api. For other cases, that would depend on the driver. A driver simulating JSDOM/CSSOM might also be able to simulate visibility. Drivers interacting with plain html might simply return "true" in all cases. |
We can advance this even further. Current state
@uuf6429 proposed ideaHave a parallel class tree where we declare a class for each $selector/$locator combination given to the Proposed idea modification:Why don't we combine these class trees:
Unknowns
|
Update 1:
|
The behavior we have in The only idea I could see would be that the selector interface (or a separate child interface) has a method
Conventional methods do benefit from the behavior of |
As mentioned here, eventually I ended up with an improved, (for dev point of view), element selection system on top of Mink.
Let's take a look first at how it's currently working. Let's say we want to check the result of a form submission and in particular we expect a specific text in a specific element (to avoid conflicting with other elements on the same page that may have the same text).
Mink provides quite a few methods that take
selector
andlocator
arguments. While that's not wrong, it is does have a certain learning curve. Since the documentation is a bit lacking, devs will probably have to dig a bit to find the posibilities.What I'm proposing is to have a specific data structure (class) encapsulating that selector/locator pair.
Interestingly, the code in Selector/ seems to lead in that direction, but seems to fall short of being useful to end users.
Here's a quick backward-compatible prototype of what I mean:
I'd consider adding equivalent methods to get visible elements (i.e. the element must be found and it must be visible), since in most cases, that's what testers intended and also decreases a lot of boilerplate.
voilà:
Some remaining points/questions
Not sure. It does sound a bit far fetched.
$page->fillField(..)
).While the above provides better DX (than the current selector/locator system), the conviniece methods may make more sense. I think we should keep them; at most maybe refactor them to use the new system.
I believe that anything that doesn't impact the performance of the project and that would improve DX should be added. I'm not familiar with alternatives, but if, for example, there would be a
@param-language
phpdoc for some specific IDE, I'd be fine adding them.The text was updated successfully, but these errors were encountered: