Search in sources :

Example 36 with TestBenchElement

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

the class DnDAttachDetachIT method testDnD_moveComponents_dndOperationWorks.

@Test
public void testDnD_moveComponents_dndOperationWorks() {
    open();
    dragAndDrop(getDraggableText(), getDropTarget());
    TestBenchElement eventElement = getEvent(0);
    Assert.assertEquals("Drop: 0", eventElement.getText());
    clickElementWithJs(MOVE_BUTTON_ID);
    dragAndDrop(getDraggableText(), getDropTarget());
    eventElement = getEvent(1);
    Assert.assertEquals("Drop: 1", eventElement.getText());
    Assert.assertFalse("No second event should have occurred", isElementPresent(By.id("drop-" + 2)));
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest) Test(org.junit.Test)

Example 37 with TestBenchElement

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

the class PushWithPreserveOnRefreshIT method ensurePushWorksAfterRefresh.

@Test
public void ensurePushWorksAfterRefresh() {
    open();
    WebElement loadingIndicator = findElement(By.className("v-loading-indicator"));
    waitUntil(driver -> !loadingIndicator.isDisplayed());
    TestBenchElement button = $(TestBenchElement.class).id("click");
    button.click();
    button.click();
    Assert.assertEquals("Button has been clicked 2 times", getLastLog());
    open();
    Assert.assertEquals("Button has been clicked 2 times", getLastLog());
    button = $(TestBenchElement.class).id("click");
    button.click();
    Assert.assertEquals("Button has been clicked 3 times", getLastLog());
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 38 with TestBenchElement

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

the class RemoveRoutersLayoutContentIT method assertSubLayoutHasNoOldContent.

private void assertSubLayoutHasNoOldContent() {
    TestBenchElement subLayout = $("div").id(SUB_LAYOUT_ID);
    List<WebElement> subLayoutChildren = subLayout.findElements(By.tagName("div"));
    Assert.assertEquals(1, subLayoutChildren.size());
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement)

Example 39 with TestBenchElement

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

the class ServiceWorkerIT method offlineNonRoot_reload_viewReloaded.

@Test
public void offlineNonRoot_reload_viewReloaded() throws IOException {
    getDriver().get(getRootURL() + "/");
    waitForDevServer();
    waitForServiceWorkerReady();
    // Set offline network conditions in ChromeDriver
    setConnectionType(NetworkConnection.ConnectionType.AIRPLANE_MODE);
    try {
        $("main-view").first().$("a").id("menu-another").click();
        // Wait for component inside shadow root as there is no vaadin
        // to wait for as with server-side
        waitUntil(input -> $("another-view").first().$("div").id("another-content").isDisplayed());
        // Reload the page in offline mode
        executeScript("window.location.reload();");
        waitUntil(webDriver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"));
        MatcherAssert.assertThat(getDriver().getCurrentUrl(), CoreMatchers.endsWith("/another"));
        TestBenchElement anotherView = $("another-view").first();
        Assert.assertTrue(anotherView.$("*").id("another-content").isDisplayed());
    } finally {
        // Reset network conditions back
        setConnectionType(NetworkConnection.ConnectionType.ALL);
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeDeviceTest(com.vaadin.flow.testutil.ChromeDeviceTest)

Example 40 with TestBenchElement

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

the class ServiceWorkerIT method offlineServerView_navigateToTsView_navigationSuccessful.

@Test
public void offlineServerView_navigateToTsView_navigationSuccessful() throws IOException {
    getDriver().get(getRootURL() + "/hello");
    waitForDevServer();
    waitForServiceWorkerReady();
    // Set offline network conditions in ChromeDriver
    setConnectionType(NetworkConnection.ConnectionType.AIRPLANE_MODE);
    try {
        $("main-view").first().$("a").id("menu-another").click();
        // Wait for component inside shadow root as there is no vaadin
        // to wait for as with server-side
        waitUntil(input -> $("another-view").first().$("div").id("another-content").isDisplayed());
        MatcherAssert.assertThat(getDriver().getCurrentUrl(), CoreMatchers.endsWith("/another"));
        TestBenchElement anotherView = $("another-view").first();
        Assert.assertTrue(anotherView.$("*").id("another-content").isDisplayed());
    } finally {
        // Reset network conditions back
        setConnectionType(NetworkConnection.ConnectionType.ALL);
    }
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeDeviceTest(com.vaadin.flow.testutil.ChromeDeviceTest)

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