Search in sources :

Example 81 with TestBenchElement

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

the class WebComponentIT method indexPageGetsWebComponent_attributeIsReflectedToServer.

@Test
public void indexPageGetsWebComponent_attributeIsReflectedToServer() {
    open();
    waitForElementVisible(By.id("show-message"));
    TestBenchElement showMessage = byId("show-message");
    waitUntil(driver -> showMessage.$("select").exists());
    TestBenchElement select = showMessage.$("select").first();
    // Selection is visibly changed and event manually dispatched
    // as else the change is not seen.
    getCommandExecutor().executeScript("arguments[0].value='Peter';" + "arguments[0].dispatchEvent(new Event('change'));", select);
    Assert.assertEquals("Selected: Peter, Parker", showMessage.$("span").first().getText());
    TestBenchElement noMessage = byId("no-message");
    select = noMessage.$("select").first();
    getCommandExecutor().executeScript("arguments[0].value='Peter';" + "arguments[0].dispatchEvent(new Event('change'));", select);
    Assert.assertFalse("Message should not be visible", noMessage.$("span").first().isDisplayed());
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 82 with TestBenchElement

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

the class FeatureIT method toggleViteFeature.

private void toggleViteFeature(boolean expectedInitialState) {
    DevModeGizmoElement gizmo = $(DevModeGizmoElement.class).waitForFirst();
    gizmo.expand();
    gizmo.$(NativeButtonElement.class).id("features").click();
    TestBenchElement toggleButton = gizmo.$(TestBenchElement.class).id("feature-toggle-viteForFrontendBuild");
    String checked = getCommandExecutor().executeScript("return arguments[0].checked", toggleButton).toString();
    Assert.assertEquals("Toggle button state expected " + expectedInitialState, Boolean.toString(expectedInitialState), checked);
    toggleButton.click();
}
Also used : DevModeGizmoElement(com.vaadin.flow.testutil.DevModeGizmoElement) TestBenchElement(com.vaadin.testbench.TestBenchElement)

Example 83 with TestBenchElement

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

the class EmbeddedWebComponentIT method servletPageGetsWebComponent_attributeIsReflectedToServer.

@Test
public void servletPageGetsWebComponent_attributeIsReflectedToServer() {
    open();
    // Check that there is no pwa install prompt
    Assert.assertFalse(isElementPresent(By.id("pwa-ip")));
    TestBenchElement webComponent = $("client-select").first();
    Assert.assertTrue(webComponent.getText().trim().startsWith("Web Component"));
    // Selection is visibly changed and event manually dispatched
    // as else the change is not seen.
    getCommandExecutor().executeScript("arguments[0].value='Peter';" + "arguments[0].dispatchEvent(new Event('change'));", webComponent.$("select").first());
    TestBenchElement msg = webComponent.$("span").first();
    Assert.assertEquals("Selected: Peter, Parker", msg.getText());
    // Check that there is correctly imported custom element
    TestBenchElement dependencyElement = webComponent.$("dep-element").first();
    Assert.assertEquals("Imported element", byId(dependencyElement, "main").getText());
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 84 with TestBenchElement

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

the class FireEventIT method customEventsGetSentToTheClientSide.

@Test
public void customEventsGetSentToTheClientSide() {
    open();
    waitForElementVisible(By.id("calc"));
    TestBenchElement calc = byId("calc");
    TestBenchElement button = byId("calc", "button");
    TestBenchElement number1 = byId("calc", N1);
    TestBenchElement number2 = byId("calc", N2);
    Assert.assertEquals("Sum should be 0", "0", value(SUM));
    Assert.assertEquals("Error should be empty", "", value(ERR));
    number1.sendKeys("4.5", Keys.ENTER);
    number2.sendKeys("3.5", Keys.ENTER);
    button.click();
    Assert.assertEquals("Sum should be 8", "8", value(SUM));
    Assert.assertEquals("Error should be empty", "", value(ERR));
    number1.clear();
    number2.clear();
    Assert.assertEquals("", value(number1));
    Assert.assertEquals("", value(number2));
    button.click();
    Assert.assertEquals("Sum should not have changed", "8", value(SUM));
    Assert.assertEquals("Error should have been raised", "empty String", value(ERR));
    number1.sendKeys("99", Keys.ENTER);
    number2.sendKeys("101", Keys.ENTER);
    button.click();
    Assert.assertEquals("Sum should be 200", "200", value(SUM));
}
Also used : TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 85 with TestBenchElement

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

the class NpmOnlyIndexIT method globalStylesAreUnderTheWebComponent.

// test for #7005
@Test
public void globalStylesAreUnderTheWebComponent() {
    open();
    waitForElementVisible(By.tagName("themed-web-component"));
    TestBenchElement webComponent = $("themed-web-component").first();
    List<TestBenchElement> styles = webComponent.$("style").all();
    System.out.println(styles.size());
    // getAttribute wouldn't work, so we are counting the elements
    Assert.assertEquals(2, styles.size());
}
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