-
Notifications
You must be signed in to change notification settings - Fork 22
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
Comments
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 |
…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
) 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
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 instanceclick(checkbox(near("search"))
.Both would allow for a more natural selection of elements.
(Examples were taken from https://taiko.gauge.org/#smart-selectors)
The text was updated successfully, but these errors were encountered: