Search in sources :

Example 66 with TestBenchElement

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

the class DomRepeatIT method checkThatIndicesAreCorrect.

@Test
public void checkThatIndicesAreCorrect() {
    open();
    TestBenchElement template = $(TestBenchElement.class).id("template");
    for (int i = 0; i < DomRepeatView.NUMBER_OF_EMPLOYEES; i++) {
        template.$(TestBenchElement.class).id(DomRepeatView.TR_ID_PREFIX + i).click();
        String eventIndex = template.$(TestBenchElement.class).id(DomRepeatView.EVENT_INDEX_ID).getText();
        String repeatIndex = template.$(TestBenchElement.class).id(DomRepeatView.REPEAT_INDEX_ID).getText();
        Assert.assertEquals(eventIndex, repeatIndex);
        Assert.assertEquals(i, Integer.parseInt(repeatIndex));
    }
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 67 with TestBenchElement

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

the class EventHandlerIT method handleEventOnServer.

@Test
public void handleEventOnServer() {
    open();
    TestBenchElement template = $(TestBenchElement.class).id("template");
    template.$(TestBenchElement.class).id("handle").click();
    Assert.assertTrue("Unable to find server event handler invocation confirmation. " + "Looks like 'click' event handler has not been invoked on the server side", isElementPresent(By.id("event-handler-result")));
    template.$(TestBenchElement.class).id("send").click();
    TestBenchElement container = $(TestBenchElement.class).id("event-data");
    List<TestBenchElement> divs = container.$("div").all();
    Assert.assertEquals("Unexpected 'button' event data in the received event handler parameter", "button: 0", divs.get(1).getText());
    Assert.assertEquals("Unexpected 'type' event data in the received event handler parameter", "type: click", divs.get(2).getText());
    Assert.assertEquals("Unexpected 'tag' event data in the received event handler parameter", "tag: button", divs.get(3).getText());
    // Check event functionality for event with both client and server
    // handler
    template.$(TestBenchElement.class).id("overridden").click();
    Assert.assertTrue("Unable to find server event handler invocation confirmation.", isElementPresent(By.id("overridden-event-handler-result")));
    Assert.assertEquals("Received result wasn't updated by client!", "Overridden server event was invoked with result: ClientSide handler", findElement(By.id("overridden-event-handler-result")).getText());
    // @ClientCallable return value
    template.$("button").id("client").click();
    Assert.assertEquals("Server-side message should be present", "Call from client, message: foo, true", $("div").id("client-call").getText());
    Assert.assertEquals("Message from awaiting return value should be present", "FOO", template.$("span").id("status").getText());
    template.$("button").id("clientError").click();
    Assert.assertEquals("Message from awaiting exception should be present", "Error: Something went wrong. Check server-side logs for more information.", template.$("span").id("status").getText());
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 68 with TestBenchElement

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

the class BeanInListingIT method beanInTwoWayBinding.

@Test
public void beanInTwoWayBinding() throws InterruptedException {
    open();
    TestBenchElement selected = $(TestBenchElement.class).id("template").$(TestBenchElement.class).id("selected");
    assertSelectionValue("user-item", selected, "foo");
    assertSelectionValue("user-item", selected, "bar");
    assertSelectionValue("msg-item", selected, "baz");
    assertSelectionValue("msg-item", selected, "msg");
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 69 with TestBenchElement

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

the class ChildOrderIT method prependTextsFromServer_textsAreAddedBeforeExistingOnes.

@Test
public void prependTextsFromServer_textsAreAddedBeforeExistingOnes() {
    TestBenchElement container = root.$(TestBenchElement.class).id("containerWithText");
    assertNodeOrder(container, "Client text");
    clickAndWaitForContainerToChange(container, "prependChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 1");
    clickAndWaitForContainerToChange(container, "prependChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 2", "Server text 1");
    clickAndWaitForContainerToChange(container, "addClientSideChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 2", "Server text 1", "Client text");
    clickAndWaitForContainerToChange(container, "prependChildToContainer2");
    assertNodeOrder(container, "Client text", "Server text 3", "Server text 2", "Server text 1", "Client text");
    clickAndWaitForContainerToChange(container, "removeChildFromContainer2");
    assertNodeOrder(container, "Client text", "Server text 3", "Server text 2", "Client text");
    clickAndWaitForContainerToChange(container, "removeChildFromContainer2");
    assertNodeOrder(container, "Client text", "Server text 3", "Client text");
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 70 with TestBenchElement

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

the class ChildOrderIT method clickAndWaitForContainerToChange.

private void clickAndWaitForContainerToChange(WebElement container, String buttonToclick) {
    String innertText = container.getAttribute("innerText");
    TestBenchElement button = root.$(TestBenchElement.class).id(buttonToclick);
    button.click();
    waitUntilNot(driver -> container.getAttribute("innerText").equals(innertText));
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement)

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