Search in sources :

Example 1 with LabelElement

use of com.vaadin.flow.component.html.testbench.LabelElement in project flow by vaadin.

the class AttachExistingElementIT method attachExistingElement.

@Test
public void attachExistingElement() {
    open();
    // attach label
    findElement(By.id("attach-label")).click();
    Assert.assertTrue(isElementPresent(By.id("label")));
    WebElement label = findElement(By.id("label"));
    Assert.assertEquals("label", label.getTagName().toLowerCase(Locale.ENGLISH));
    WebElement parentDiv = findElement(By.id("root-div"));
    List<WebElement> children = parentDiv.findElements(By.xpath("./child::*"));
    boolean labelIsFoundAsChild = false;
    WebElement removeButton = null;
    for (int i = 0; i < children.size(); i++) {
        WebElement child = children.get(i);
        if (child.equals(label)) {
            labelIsFoundAsChild = true;
            WebElement attachButton = children.get(i + 1);
            Assert.assertEquals("The first inserted component after " + "attached label has wrong index on the client side", "attach-populated-label", attachButton.getAttribute("id"));
            removeButton = children.get(i + 2);
            Assert.assertEquals("The second inserted component after " + "attached label has wrong index on the client side", "remove-self", removeButton.getAttribute("id"));
            break;
        }
    }
    Assert.assertTrue("The attached label is not found as a child of its parent", labelIsFoundAsChild);
    removeButton.click();
    Assert.assertFalse(isElementPresent(By.id("remove-self")));
    // attach existing server-side element
    findElement(By.id("attach-populated-label")).click();
    Assert.assertEquals("already-populated", label.getAttribute("class"));
    // attach header element
    findElement(By.id("attach-header")).click();
    Assert.assertTrue(isElementPresent(By.id("header")));
    Assert.assertEquals("h1", findElement(By.id("header")).getTagName().toLowerCase(Locale.ENGLISH));
    // attach a child in the shadow root of the div
    findElement(By.id("attach-label-inshadow")).click();
    LabelElement labelInShadow = $(DivElement.class).id("element-with-shadow").$(LabelElement.class).id("label-in-shadow");
    Assert.assertEquals("label", labelInShadow.getTagName().toLowerCase(Locale.ENGLISH));
    // Try to attach non-existing element
    findElement(By.id("non-existing-element")).click();
    Assert.assertTrue(isElementPresent(By.id("non-existing-element")));
}
Also used : DivElement(com.vaadin.flow.component.html.testbench.DivElement) LabelElement(com.vaadin.flow.component.html.testbench.LabelElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Aggregations

DivElement (com.vaadin.flow.component.html.testbench.DivElement)1 LabelElement (com.vaadin.flow.component.html.testbench.LabelElement)1 ChromeBrowserTest (com.vaadin.flow.testutil.ChromeBrowserTest)1 Test (org.junit.Test)1 WebElement (org.openqa.selenium.WebElement)1