Search in sources :

Example 71 with TestBenchElement

use of com.vaadin.testbench.TestBenchElement in project flow by vaadin.

the class ChildOrderIT method prependElementsFromServer_elementsAreAddedBeforeExistingOnes.

@Test
public void prependElementsFromServer_elementsAreAddedBeforeExistingOnes() {
    TestBenchElement container = root.$(TestBenchElement.class).id("containerWithElement");
    assertNodeOrder(container, "Client child");
    clickAndWaitForContainerToChange(container, "prependChildToContainer1");
    assertNodeOrder(container, "Client child", "Server child 1");
    clickAndWaitForContainerToChange(container, "prependChildToContainer1");
    assertNodeOrder(container, "Client child", "Server child 2", "Server child 1");
    clickAndWaitForContainerToChange(container, "addClientSideChildToContainer1");
    assertNodeOrder(container, "Client child", "Server child 2", "Server child 1", "Client child");
    clickAndWaitForContainerToChange(container, "prependChildToContainer1");
    assertNodeOrder(container, "Client child", "Server child 3", "Server child 2", "Server child 1", "Client child");
    clickAndWaitForContainerToChange(container, "removeChildFromContainer1");
    assertNodeOrder(container, "Client child", "Server child 3", "Server child 2", "Client child");
    clickAndWaitForContainerToChange(container, "removeChildFromContainer1");
    assertNodeOrder(container, "Client child", "Server child 3", "Client child");
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 72 with TestBenchElement

use of com.vaadin.testbench.TestBenchElement in project flow by vaadin.

the class ChildOrderIT method appendTextsFromServer_textsAreAddedAfterExistingOnes.

@Test
public void appendTextsFromServer_textsAreAddedAfterExistingOnes() {
    TestBenchElement container = root.$(TestBenchElement.class).id("containerWithText");
    assertNodeOrder(container, "Client text");
    clickAndWaitForContainerToChange(container, "addChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 1");
    clickAndWaitForContainerToChange(container, "addChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 1", "Server text 2");
    clickAndWaitForContainerToChange(container, "addClientSideChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 1", "Server text 2", "Client text");
    /*
         * Client side nodes added after the server side ones are not considered
         * in the counting, so they are left behind
         */
    clickAndWaitForContainerToChange(container, "addChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 1", "Server text 2", "Server text 3", "Client text");
    clickAndWaitForContainerToChange(container, "removeChildFromContainer2");
    assertNodeOrder(container, "Client text", "Server text 1", "Server text 2", "Client text");
    clickAndWaitForContainerToChange(container, "removeChildFromContainer2");
    assertNodeOrder(container, "Client text", "Server text 1", "Client text");
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 73 with TestBenchElement

use of com.vaadin.testbench.TestBenchElement in project flow by vaadin.

the class InjectScriptTagIT method openPage_scriptIsEscaped.

@Test
public void openPage_scriptIsEscaped() {
    open();
    TestBenchElement parent = $("inject-script-tag-template").first();
    TestBenchElement div = parent.$(TestBenchElement.class).id("value-div");
    Assert.assertEquals("<!-- <script>", div.getText());
    WebElement slot = findElement(By.id("slot-1"));
    Assert.assertEquals("<!-- <script> --><!-- <script></script>", slot.getText());
    TestBenchElement button = parent.$(TestBenchElement.class).id("change-value");
    button.click();
    Assert.assertEquals("<!-- <SCRIPT>", div.getText());
    slot = findElement(By.id("slot-2"));
    Assert.assertEquals("<!-- <SCRIPT> --><!-- <SCRIPT></SCRIPT>", slot.getText());
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 74 with TestBenchElement

use of com.vaadin.testbench.TestBenchElement in project flow by vaadin.

the class InjectsJsTemplateIT method executeJsOnInjectedElement.

@Test
public void executeJsOnInjectedElement() {
    open();
    TestBenchElement parent = $("injects-js-template").first();
    TestBenchElement injectedTemplate = parent.$(TestBenchElement.class).id("injected-template");
    WebElement fooLabel = injectedTemplate.$(TestBenchElement.class).id("foo-prop");
    Assert.assertEquals("bar", fooLabel.getText());
    WebElement bazLabel = injectedTemplate.$(TestBenchElement.class).id("baz-prop");
    Assert.assertEquals("setFromParent", bazLabel.getText());
    WebElement injectedDiv = parent.$(TestBenchElement.class).id("injected-div");
    Assert.assertEquals("setFromParent", injectedDiv.getAttribute("class"));
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 75 with TestBenchElement

use of com.vaadin.testbench.TestBenchElement in project flow by vaadin.

the class JsGrandParentIT method callJsInsideGrandInjected.

@Test
public void callJsInsideGrandInjected() {
    open();
    TestBenchElement parent = $("js-grand-parent").first();
    TestBenchElement child = parent.$("js-sub-template").first();
    TestBenchElement grandChild = child.$("js-injected-grand-child").first();
    WebElement label = grandChild.$(TestBenchElement.class).id("foo-prop");
    waitUntil(driver -> "bar".equals(label.getText()));
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Aggregations

TestBenchElement (com.vaadin.testbench.TestBenchElement)154 Test (org.junit.Test)120 ChromeBrowserTest (com.vaadin.flow.testutil.ChromeBrowserTest)98 WebElement (org.openqa.selenium.WebElement)46 By (org.openqa.selenium.By)6 DivElement (com.vaadin.flow.component.html.testbench.DivElement)5 List (java.util.List)5 Assert (org.junit.Assert)5 SpanElement (com.vaadin.flow.component.html.testbench.SpanElement)4 ChromeDeviceTest (com.vaadin.flow.testutil.ChromeDeviceTest)4 NativeButtonElement (com.vaadin.flow.component.html.testbench.NativeButtonElement)3 File (java.io.File)3 Ignore (org.junit.Ignore)3 ButtonElement (com.vaadin.flow.component.button.testbench.ButtonElement)2 DevModeGizmoElement (com.vaadin.flow.testutil.DevModeGizmoElement)2 Optional (java.util.Optional)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)2 WebDriver (org.openqa.selenium.WebDriver)2 ParagraphElement (com.vaadin.flow.component.html.testbench.ParagraphElement)1 TextFieldElement (com.vaadin.flow.component.textfield.testbench.TextFieldElement)1