Search in sources :

Example 76 with TestBenchElement

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

the class AfterServerChangesIT method assertAfterServerUpdate.

private void assertAfterServerUpdate(TestBenchElement element, int i) {
    WebElement count = element.$(TestBenchElement.class).id("count");
    Assert.assertEquals(String.valueOf(i), count.getText());
    WebElement delta = element.$(TestBenchElement.class).id("delta");
    Assert.assertEquals(Boolean.TRUE.toString(), delta.getText());
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement)

Example 77 with TestBenchElement

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

the class AfterServerChangesIT method notifyServerUpdateOnTheClientSide.

@Test
public void notifyServerUpdateOnTheClientSide() {
    open();
    List<TestBenchElement> components = $("after-server-changes").all();
    components.forEach(component -> assertAfterServerUpdate(component, 1));
    WebElement update = findElement(By.id("update"));
    update.click();
    components.forEach(component -> assertAfterServerUpdate(component, 2));
    findElement(By.id("remove")).click();
    update.click();
    // The second components is removed
    // No exceptions , everything is functional
    assertAfterServerUpdate($("after-server-changes").first(), 3);
}
Also used : WebElement(org.openqa.selenium.WebElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 78 with TestBenchElement

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

the class DebugWindowErrorHandlingIT method causeErrors.

private void causeErrors(String nr) {
    TestBenchElement input = $("input").id(DebugWindowErrorHandlingView.NUMBER_OF_ERRORS_ID);
    // input.setProperty("value", i);
    input.clear();
    input.sendKeys(nr);
    input.sendKeys(Keys.TAB);
    $(NativeButtonElement.class).id(DebugWindowErrorHandlingView.CAUSE_ERRORS_ID).click();
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement)

Example 79 with TestBenchElement

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

the class PreserveOnRefreshIT method openingToAnotherPageWithSameComponents_should_preserveComponentWithoutChangedIdAttribute.

@Test
public void openingToAnotherPageWithSameComponents_should_preserveComponentWithoutChangedIdAttribute() {
    /*
         * Currently, when preserving exported components, they are identified
         * by window name, component's tag, and generated id of the embedded web
         * component or id of the wrapping element (if available). Since windows
         * name does not necessarily change when page changes, and generated id
         * is only defined by type of the web component and its order on the
         * page, the component cannot be reliably identified uniquely. In order
         * to assure uniqueness, the user must provide id for the component. If
         * if is provided, the uniqueness can be assured between pages. Contents
         * are synchronized between locations in two cases: - embedded element
         * has the same id as its counter-part in the different location. -
         * component does not have user-assigned id and has the same generated
         * id on both locations (this happens, if the component has the same
         * counted index within the component type between pages)
         */
    final String TEXT_CONTENTS = "black cat";
    TestBenchElement noIdElement = findTagWithoutId(PRESERVE_ON_REFRESH_TAG);
    Assert.assertEquals(MODIFIED + " input should be empty", "", getValue(MODIFIED));
    Assert.assertEquals(UNMODIFIED + " input should be empty", "", getValue(UNMODIFIED));
    Assert.assertEquals("Input without id should be empty", "", getValue(noIdElement));
    writeInInput(MODIFIED, TEXT_CONTENTS);
    writeInInput(UNMODIFIED, TEXT_CONTENTS);
    writeInInput(noIdElement, TEXT_CONTENTS);
    relocateTo("preserveOnRefreshSecondary.html");
    // same place, same id
    Assert.assertEquals(MODIFIED + " input should have preserved state", TEXT_CONTENTS, getValue(MODIFIED));
    // same place, different id
    Assert.assertEquals(NEW_ID + " input should be empty", "", getValue(NEW_ID));
    // same place, no assigned id
    TestBenchElement noIdElement2 = findTagWithoutId(PRESERVE_ON_REFRESH_TAG);
    Assert.assertEquals("Input without id should have preserved state", TEXT_CONTENTS, getValue(noIdElement2));
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 80 with TestBenchElement

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

the class WebComponentIT method indexPageGetsThemedWebComponent_themeIsApplied.

@Test
public void indexPageGetsThemedWebComponent_themeIsApplied() {
    open();
    waitForElementVisible(By.tagName("themed-web-component"));
    TestBenchElement webComponent = $("themed-web-component").first();
    TestBenchElement themedComponent = webComponent.$("themed-component").first();
    TestBenchElement content = themedComponent.$("div").first();
    Assert.assertNotNull("The component which should use theme doesn't " + "contain elements", content);
    Assert.assertEquals("rgba(255, 0, 0, 1)", content.getCssValue("color"));
}
Also used : 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