Search in sources :

Example 41 with TestBenchElement

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

the class ServiceWorkerIT method offlineTsView_navigateToOtherTsView_navigationSuccessful.

@Test
public void offlineTsView_navigateToOtherTsView_navigationSuccessful() throws IOException {
    getDriver().get(getRootURL() + "/about");
    waitForDevServer();
    waitForServiceWorkerReady();
    MatcherAssert.assertThat(getDriver().getCurrentUrl(), CoreMatchers.endsWith("/about"));
    // 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)

Example 42 with TestBenchElement

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

the class NavigateBetweenViewsIT method openFlowView_isConnectedOnAttach.

@Test
public void openFlowView_isConnectedOnAttach() {
    getDriver().get(getRootURL() + "/hello");
    waitForDevServer();
    Assert.assertThat(getDriver().getCurrentUrl(), CoreMatchers.endsWith("/hello"));
    assertIsConnected();
    // Navigate away and back
    $(NativeButtonElement.class).id(NAVIGATE_ABOUT).click();
    waitUntil(input -> $("about-view").first().$("a").id("navigate-hello").isDisplayed());
    TestBenchElement aboutView = $("about-view").first();
    aboutView.$("*").id("navigate-hello").click();
    assertIsConnected();
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 43 with TestBenchElement

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

the class ParentThemeIT method componentThemeIsApplied_childThemeTextColorIsApplied.

@Test
public void componentThemeIsApplied_childThemeTextColorIsApplied() {
    open();
    TestBenchElement myField = $(TestBenchElement.class).id(MY_POLYMER_ID);
    TestBenchElement input = myField.$("vaadin-input-container").attribute("part", "input-field").first();
    Assert.assertEquals("Polymer text field should have red background", "rgba(255, 0, 0, 1)", input.getCssValue("background-color"));
    Assert.assertEquals("Text field should have color as green", "rgba(0, 128, 0, 1)", input.getCssValue("color"));
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 44 with TestBenchElement

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

the class FrontendLiveReloadIT method liveReloadOnTouchedFrontendFile.

@Test
public void liveReloadOnTouchedFrontendFile() {
    open();
    // when: the frontend code is updated
    WebElement codeField = findElement(By.id(FrontendLiveReloadView.FRONTEND_CODE_TEXT));
    String oldCode = getValue(codeField);
    String newCode = oldCode.replace("Custom component contents", "Updated component contents");
    codeField.clear();
    codeField.sendKeys(newCode);
    waitForElementPresent(By.id(FrontendLiveReloadView.FRONTEND_CODE_UPDATE_BUTTON));
    WebElement liveReloadTrigger = findElement(By.id(FrontendLiveReloadView.FRONTEND_CODE_UPDATE_BUTTON));
    liveReloadTrigger.click();
    // when: the page has reloaded
    waitForLiveReload();
    // then: the frontend changes are visible in the DOM
    TestBenchElement customComponent = $("*").id(FrontendLiveReloadView.CUSTOM_COMPONENT);
    TestBenchElement embeddedDiv = customComponent.$("*").id("custom-div");
    Assert.assertEquals("Updated component contents", embeddedDiv.getText());
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test)

Example 45 with TestBenchElement

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

the class ApplicationThemeComponentIT method componentThemeIsApplied.

@Test
public void componentThemeIsApplied() {
    open();
    final TestBenchElement themedComponent = $("themed-component").first();
    final TestBenchElement embeddedComponent = themedComponent.$(DivElement.class).id(EMBEDDED_ID);
    TestBenchElement myField = embeddedComponent.$(TestBenchElement.class).id(MY_COMPONENT_ID);
    TestBenchElement input = myField.$("vaadin-input-container").attribute("part", "input-field").first();
    Assert.assertEquals("Polymer text field should have red background", "rgba(255, 0, 0, 1)", input.getCssValue("background-color"));
}
Also used : DivElement(com.vaadin.flow.component.html.testbench.DivElement) 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