Reputation: 1
I'm developing tests with Vaadin TestBench and I'm having difficulties with a particular scenario. For the given generated HTML (adapted from a vaadin/vcf-nav GitHub repository example):
<vcf-nav collapsible>
<span slot="label">Main menu</span>
<vcf-nav-item id="dashboard" path="/dashboard">
<vaadin-icon icon="vaadin:chart" slot="prefix"></vaadin-icon>
Dashboard
<span theme="badge primary" slot="suffix" aria-label="(2 new items)">2</span>
</vcf-nav-item>
<vcf-nav-item id="parent">
<vaadin-icon icon="vaadin:folder-open" slot="prefix"></vaadin-icon>
Parent
<vcf-nav-item id="child1" path="/child1" slot="children">
Child 1
</vcf-nav-item>
<vcf-nav-item id="child2" path="/child2" slot="children">
Child 2
</vcf-nav-item>
</vcf-nav-item>
</vcf-nav>
When testing a simple vcf-nav-item
the getText()
method returns the expected result. Ex:.
AppNavItemElement menuItem = $(MainLayoutElement.class).first()
.$(ScrollerElement.class).first()
.$(AppNavItemElement.class).id("dashboard");
Assert.assertEquals("Dashboard", menuItem.getText());
The problem occurs on a vcf-nav-item
with child items, in which case the gettext
methods returns a concatenation of the parent text and all the children: "ParentChild 1Child 2".
AppNavItemElement menuItem = $(MainLayoutElement.class).first()
.$(ScrollerElement.class).first()
.$(AppNavItemElement.class).id("parent");
Assert.assertEquals("Parent", menuItem.getText());
I created a custom AppNavItemElement
class with an override to the getText()
method as follow:
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elementsbase.Element;
@Element("vcf-nav-item")
public class AppNavItemElement extends TestBenchElement {
@Override
public String getText() {
return this.getPropertyString("textContent");
}
}
Upvotes: 0
Views: 81