A) Is Vaadin's setId() function [1] suitable for creating component IDs that are friendly for test automation?
Indeed, it has replaced the deprecated setDebugId()
. According to its javadoc:
Description copied from interface: com.vaadin.ui.Component
Adds a unique id for the component that is used on the client-side for testing purposes. It is the responsibility of the programmer to ensure identifiers remain unique.
We did not implement any kind of automated "naming strategy framework" as mentioned in your third resource. Instead, we manually assigned component IDs based on internal agreement. It should be noted that not all components can have IDs, such as menu items.
B) Can Vaadin's addStyleName() or setStyleName() be useful for creating a custom CSS style that could later be utilized as an ID?
While possible, it is similar to A). In this case, you can locate elements using
findElement(By.className("some-class"))
;
public static By className(@NotNull String className)
Finds elements based on the value of the "class" attribute. If an element has multiple classes, each will be matched against individually. For example, if the value is "one two onone," both "one" and "two" will match.
Another approach would be using xpath, such as
findElement(By.xpath("//*[contains(@class, 'column-hiding-toggle')]/span/div[text()='Name']"))
.
Although xpath is powerful and versatile (both By.id
& By.className
likely use xpaths internally), it may require frequent updates if the structure of your user interfaces changes frequently, leading to potential maintenance challenges.