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

Add the capability to filter elements by their visibility #1018

Closed
miherlosev opened this issue Dec 1, 2016 · 20 comments
Closed

Add the capability to filter elements by their visibility #1018

miherlosev opened this issue Dec 1, 2016 · 20 comments
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: enhancement The accepted proposal for future implementation.
Milestone

Comments

@miherlosev
Copy link
Collaborator

miherlosev commented Dec 1, 2016

:hidden Selector - https://api.jquery.com/hidden-selector/
:visible Selector - https://api.jquery.com/visible-selector/

Updated:
Finally we plan to use the following syntax:

Selector('.hey').filterVisible()
Selector('.hey').filterHidden()
@inikulin
Copy link
Contributor

inikulin commented Dec 1, 2016

These pseduo-selectors are not a part of any CSS spec and implementing them as pseudo-selectors will be quite complicated since we'll need to parse queries. We can introduce filter method instead:

Selector('.hey').hidden(true); // default
Selector('.hey').hidden(false);

Note that we can't use visible filter since there is a shorthand property with the same name.

@VasilyStrelyaev
Copy link
Contributor

What do you think we should use instead of visible?
I guess visible is the only right word for this, so we will have to take something not quite correct yet simple enough.

Is it

  1. displayed
  2. shown (plays sort of nice with hidden)
  3. ..?

@AlexanderMoskovkin
Copy link
Contributor

I think visible, displayed and shown are to similar and can make more confusion. I prefer hidden

@inikulin
Copy link
Contributor

inikulin commented Sep 20, 2017

Selector('.hey').filterVisible()
Selector('.hey').filterHidden()

@miherlosev
Copy link
Collaborator Author

In most cases we need a visible and accessible element (in viewport and etc.),
so I prefer Selector('.class').visible(true|false)

@inikulin
Copy link
Contributor

@VasilyStrelyaev
Copy link
Contributor

Oh, after reading the user's issue I thought we were going to have two methods with bool parameters like hidden(bool) and visible(bool) and I was going to ask what's the difference between hidden(false) and visible(true).

It turns out that we don't. So, we need either two methods with no parameters or one parameterized.

Yet I can't choose between hidden(bool) and filterVisible + filterHidden

@miherlosev
Copy link
Collaborator Author

miherlosev commented Sep 20, 2017

Note that we can't use visible filter since there is a shorthand property with the same name.

I don't see logic problem for this (I don't know technical context).

DOMNode State has visible property, but Selector has visible method.

@inikulin
Copy link
Contributor

@miherlosev Apart from it being a bad design decision for the API:

If you need to get the entire DOM element state, call the selector with the await keyword like you would do with regular async functions. It returns a DOM Node Snapshot that contains all property values exposed by the selector in a single object.

in https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors.html#dom-node-snapshot (BTW, section that explains selector properties points to the DOM Node snapshot, so it's not quite clear that we expose these properties on Selector as well \cc @VasilyStrelyaev)

@VasilyStrelyaev
Copy link
Contributor

VasilyStrelyaev commented Sep 20, 2017

@inikulin The topic that lists the DOM Node State members no longer uses the word snapshot. Now we say that it lists the State API.

And that topic is linked from a section that says about the selector API.

Selectors and promises returned by selectors expose API to get the state (size, position, classes, etc.) of the matching element. See DOM Node State.

Did I get right what you were asking about?

@inikulin
Copy link
Contributor

@VasilyStrelyaev Yep, maybe it's worth mentioning that they are exposed as promises on Selectors and SelectorPromises, and as regular properties on snapshot in https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html

@AlexanderMoskovkin
Copy link
Contributor

Selector('.hey').filterVisible()
Selector('.hey').filterHidden()

Looks clear

@VasilyStrelyaev
Copy link
Contributor

Oliver suggested to refactor the entire Selectors topic (#1760) so I'll think of it as a part of this complex task.

@inikulin
Copy link
Contributor

@VasilyStrelyaev And we should deprecate snapshots and SelectorPromises for the love of god. It will significantly simplify both codebase and the API.

@AlexanderMoskovkin AlexanderMoskovkin modified the milestones: Sprint #9, Planned Sep 29, 2017
@AlexanderMoskovkin AlexanderMoskovkin self-assigned this Nov 24, 2017
@chit786
Copy link

chit786 commented Dec 22, 2017

How to click on this pseudo-selector, we have a situation where we have to 'click' on the pseudo selector (which is basically an icon). Any suggestion?

@chit786
Copy link

chit786 commented Dec 22, 2017

Currently this is how I am clicking on the element

await t
    .hover(Selector('div.display.inline-textarea'));

            const clickedElem = await t.eval(() => document.getElementsByClassName('release-description')[0]
                .getElementsByClassName('edit-icon')[0].click());

@AndreyBelym
Copy link
Contributor

What do you call a pseudo selector? Could you give a part of the HTML markup?

From you code, they looks like regular CSS classes, so you would write something like

await t.click('release-description edit-icon');

@mkubrycz
Copy link

As a temporary workaround for this issue I'm using this module, maybe someone here will find it helpful

@AlexanderMoskovkin AlexanderMoskovkin changed the title Add visibility filter pseudo-selectors like in JQuery Add the capability to filter elements by their visibility Jan 22, 2018
@lock
Copy link

lock bot commented Mar 28, 2019

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.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

7 participants