Search in sources :

Example 6 with ButtonElement

use of com.vaadin.flow.component.button.testbench.ButtonElement in project flow by vaadin.

the class UIAccessContextIT method securityContextSetForUIAccess.

@Test
public void securityContextSetForUIAccess() throws Exception {
    String expectedUserBalance = "Hello John the User, your bank account balance is $10000.00.";
    String expectedAdminBalance = "Hello Emma the Admin, your bank account balance is $200000.00.";
    WebDriver adminBrowser = getDriver();
    try {
        super.setup();
        open("private");
        loginUser();
        TestBenchElement balance = $("span").id("balanceText");
        Assert.assertEquals(expectedUserBalance, balance.getText());
        open("private", adminBrowser);
        HasElementQuery adminContext = new HasElementQuery() {

            @Override
            public SearchContext getContext() {
                return adminBrowser;
            }
        };
        loginAdmin(adminContext);
        TestBenchElement adminBalance = adminContext.$("span").id("balanceText");
        Assert.assertEquals(expectedAdminBalance, adminBalance.getText());
        ButtonElement sendRefresh = $(ButtonElement.class).id("sendRefresh");
        sendRefresh.click();
        Assert.assertEquals(expectedUserBalance, balance.getText());
        Assert.assertEquals(expectedAdminBalance, adminBalance.getText());
        ButtonElement adminSendRefresh = adminContext.$(ButtonElement.class).id("sendRefresh");
        adminSendRefresh.click();
        Assert.assertEquals(expectedUserBalance, balance.getText());
        Assert.assertEquals(expectedAdminBalance, adminBalance.getText());
    } finally {
        adminBrowser.quit();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HasElementQuery(com.vaadin.testbench.HasElementQuery) ButtonElement(com.vaadin.flow.component.button.testbench.ButtonElement) TestBenchElement(com.vaadin.testbench.TestBenchElement) Test(org.junit.Test)

Aggregations

ButtonElement (com.vaadin.flow.component.button.testbench.ButtonElement)6 Test (org.junit.Test)6 NotificationElement (com.vaadin.flow.component.notification.testbench.NotificationElement)4 ChromeBrowserTest (com.vaadin.flow.testutil.ChromeBrowserTest)3 TestBenchElement (com.vaadin.testbench.TestBenchElement)2 TextFieldElement (com.vaadin.flow.component.textfield.testbench.TextFieldElement)1 HasElementQuery (com.vaadin.testbench.HasElementQuery)1 WebDriver (org.openqa.selenium.WebDriver)1