nablex
nablex

Reputation: 4767

How to easily get vaadin testbench queries?

I've seen that vaadin testbench adds an extension of the By class available in selenium that allows you to do By.vaadin() which in theory is more awesome than the selenium counterparts.

The only problem I'm having is...how do I (or more specifically a tester) construct a query that is readable by By.vaadin()? For selenium you use the selenium IDE where you can point at an element, how do you do the same for vaadin?

I've started the application in debug mode but the console seems to generate java code:

ButtonElement button1 = $(TabSheetElement.class).id("MainTabSheet")
    .$(HorizontalLayoutElement.class)
    .$$(HorizontalLayoutElement.class).$$(ButtonElement.class).first();

According to the documentation (http://vaadin.com/download/book-of-vaadin/current-br/html/testbench.selectors.html) you need a selector in the form of:

 "bookexamplestobetested::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]"

So how do you construct such a query? Preferably in a point-and-click kind of way?

Upvotes: 0

Views: 713

Answers (1)

Vojtech Ruzicka
Vojtech Ruzicka

Reputation: 17095

As explained here

A Vaadin selector begins with a UI identifier. It is the URL path of the UI, but without any slashes or other special characters. For example, /book-examples/tobetested would be bookexamplestobetested. After the identifier, comes two colons "::", followed by a slash-delimited component path to the component to be selected. The elements in the component path are client-side classes of the Vaadin user interfacer components. For example, the server-side VerticalLayout component has VVerticalLayout client-side counterpart. All path elements except the leaves are component containers, usually layouts. The exact contained component is identified by its index in brackets. bookexamplestobetested::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]

However I would reconsider using such detailed selector in your Web Tests as it have many disadvantages. Your tests have hard dependency on name of your UI, structure of your layouts and component hierarchy. Much more flexible approach is to identify items in a way that has no knowledge about position of component in layout hierarchy and refers only to components html element id, unique css class, or maybe location attribute from CustomLayout. This Way your web tests are much simpler and change resistant. When you change your layouts, reorder components or add some more, your tests will not break. So you can use regular WebDriver selectors like By.ById, By.ByClassName and such.

Upvotes: 0

Related Questions