Search in sources :

Example 1 with HasElementQuery

use of com.vaadin.testbench.HasElementQuery 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)1 HasElementQuery (com.vaadin.testbench.HasElementQuery)1 TestBenchElement (com.vaadin.testbench.TestBenchElement)1 Test (org.junit.Test)1 WebDriver (org.openqa.selenium.WebDriver)1