-
Notifications
You must be signed in to change notification settings - Fork 673
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
Redesign a selector's system #798
Comments
👍 Looks good
const getElementById = Selector(id => document.querySelector(`#${id}`));
const getStatusBtn = Selector(() => getElementById('statusBtn'), { dependencies: { getElementById } }); As a see we can't get rid of dependencies in this case or we can? |
@AlexanderMoskovkin It's synthetic example, you can just do: const getStatusBtn = Selector('#statusBtn'); But it would be nice if you add more examples, to see how they will fit into new paradigm |
an example from our documentation: const getGridRow = Selector(n => document.getElementsByClassName('grid-row')[n]);
const getGridCell = Selector((m, n) => getGridRow(m).children[n], {
dependencies: { getGridRow }
}); |
I like it |
Looks good, but in my opinion |
maybe |
|
@helen-dikareva Correct. |
@kirovboris What do you think? Does fits well for you selector extensions? |
If we're discussing the selector extensions, not the snapshot extension, it looks useful. |
@kirovboris It applies only to selector combination. Snapshot extensions looks even more meaningful with this one. |
* [docs] Redesigned selectors docs (closes #798) * Fix broken links * Fix typo * Corrections * Getting started section updated * Some more corrections * Review remarks * Some fixes * Fix numered list * Landing page selectors article updated * Selector.md reworked * Linting fixed * Corrections * A typo fixed * selectors.md corrections * Remove obsolete info * Fix a typo
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow. |
* Deprecate old properties * Add filter methods: .nth() and .withText() * Allow unawaited Selector calls outside of test run * .find() method implemented * .parent() method implemented * .child() method implemented * .sibling() method implemented * .count and .exists properties * .find(): Don't apply implicit index when used as transitive selector, so it searches elements in all elements matching a parent selector. * Refactor derivative collection filtering code * .parent(): Filter mode * .child() and .sibling(): Filter mode * Fix lint errors * Fix texts
) * [docs] Redesigned selectors docs (closes DevExpress#798) * Fix broken links * Fix typo * Corrections * Getting started section updated * Some more corrections * Review remarks * Some fixes * Fix numered list * Landing page selectors article updated * Selector.md reworked * Linting fixed * Corrections * A typo fixed * selectors.md corrections * Remove obsolete info * Fix a typo
I've got this idea while thinking about #795 and making API examples. Currently we have selector and snapshots. Selectors are functions that allow you retrieve node state aka node snapshot. Having a node snapshot you can retrieve other snapshots in DOM hierarchy. Moreover, we are going to add
find
method that will allow you to retrieve descendants of the element represented by snapshot. There is a problem with this approach: we have everything messed up together. It's confusing and we don't have ability to implement some scenarios due to this approach. E.g. having a selectorA
how can I write selectorB
which will select some child of the element given by selectorA
? And we should be able to pass this descendant selector to action and should have all properties like regular selectors. The correct answer is that selectors should be combinable in order to reuse selectors to get nodes that are in relation with nodes, given by selector.The proposal
getParentNode
,getChildNode
,...parentNode()
descendant
andancestor
to selectorSelector.count()
method, that returns number of matching elementsSo, e.g. instead of:
We'll be able to write:
it's extremely useful e.g. in page models, there need to build relations without data actual retrieval.
I'm not sure, but seems like we can even get rid of
dependencies
with this approach.Also, we will have consistent API: selectors are all about retrieval and can be combined in the functional programming style. Snapshots are just plain data.
\cc @DevExpress/testcafe
Update (22.09.16)
Proposed API:
Deprecate snapshot hierarchy selectors (e.g.
getChildNode
)Deprecate
t.select
Deprecate
options.index
Deprecate
options.dependencies
Deprecate
options.text
Allow unawaited calls to Selector outside of test context.
Return
null
if Selector returns single node andindex
is more than 0..nth(idx)
.withText(text|re)
.find(cssSelector)
.find(filterFn)
.parent(idx = 0)
.parent(cssSelector)
.parent(filterFn)
.child(idx = 0)
.child(cssSelector)
.child(filterFn)
.sibling(idx = 0)
.sibling(cssSelector)
.sibling(filterFn)
.count
.exists
The text was updated successfully, but these errors were encountered: