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 additional selectors #1183

Closed
edler-san opened this issue Apr 30, 2019 · 1 comment · Fixed by #1784
Closed

Add additional selectors #1183

edler-san opened this issue Apr 30, 2019 · 1 comment · Fixed by #1784
Assignees

Comments

@edler-san
Copy link

Writing a testbench test requires a solid understanding of how a given Vaadin application is structured. The DX could be improved by allowing more general selectors.
For example click("foo") could click any element having the text "foo" (this could be a radio buttons or regular buttons for instance) as a text/caption.
Another example would be a near selector that simply selects the first element of a given type following a specific selection. For instance click(checkbox(near("search")).

Both would allow for a more natural selection of elements.
(Examples were taken from https://taiko.gauge.org/#smart-selectors)

@GrandyB
Copy link

GrandyB commented Jan 20, 2022

Not entirely sure about a 'click anything with this caption' kind of use case, but I can certainly say that ElementQuery#caption(String text) that the older versions of testbench that had, was certainly useful.

Currently, there isn't a way to get a ButtonElement by its caption for instance, which seems a bit wild given how common a use case this is. Either have to have a unique ID or class on every button in the system, or write some custom code that does a .all() and compares .getText() on each one, which seems a hacky/slow workaround. The element on the page itself has a 'innerText' property which could surely be wired into the attribute selector?

Another ElementQuery addition I'd like is .findOnly() (findSingle? findUnique?), which would be the same as doing Iterables.getOnlyElement($(Element.class).all()) - throwing an exception if there was more than one.

@joelpop joelpop self-assigned this Mar 22, 2024
mcollovati pushed a commit that referenced this issue Apr 8, 2024
Adds some selectors to ElementQuery (integration testing) to parallel those provided by ComponentQuery (unit testing).
In addition, it changes the default behavior of `id()` to throw an exception when multiple elements with the same id attribute are found.

Fixes #661
Part of #1183
joelpop added a commit that referenced this issue Apr 9, 2024
…dition

# Conflicts:
#	vaadin-testbench-core-junit5/src/test/java/com/vaadin/testbench/ElementQueryTest.java
#	vaadin-testbench-core/src/test/java/com/vaadin/testbench/ElementQueryTest.java
#	vaadin-testbench-integration-tests-junit5/frontend/template-view.ts
#	vaadin-testbench-integration-tests-junit5/src/test/java/com/vaadin/tests/ElementQueryIT.java
#	vaadin-testbench-integration-tests/frontend/template-view.ts
#	vaadin-testbench-integration-tests/src/test/java/com/vaadin/tests/ElementQueryIT.java
#	vaadin-testbench-shared/src/main/java/com/vaadin/testbench/ElementQuery.java
mcollovati pushed a commit that referenced this issue Apr 17, 2024
)

In contrast to ComponentQuerys of unit testing TestBench, ElementQuerys in E2E testing TestBench have (up until now) only provided attribute-based selector methods. This was expanded upon in PR #1774 to provide selector methods for common attributes, such as those for class names, theme, and id. This PR adds condition-based selector methods to ElementQuery to mirror and expand upon those of ComponentQuery. Namely:

withCondition
withPropertyValue[Containing]
withLabel[Containing]
withPlaceholder[Containing]
withCaption[Containing]
withText[Containing]

Elements having their labels in their text (such as buttons) must implement a new, method-less interface HasLabelAsText in their element tester (such as NativeButtonElement for the NativeButton component and ButtonElement for the Button component) in order for the withCaption[Containing] selectors to work for them.

This PR brings the E2E testing selectors up to par with the unit testing selectors. The only one missing is withValue.

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

Successfully merging a pull request may close this issue.

4 participants