Search in sources :

Example 1 with SeleniumWTableWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement in project wcomponents by BorderTech.

the class SimplePaginationTableWithSelectablesExample_Test method testActionConstraintsAcrossPagesWithoutRefresh.

@Test
public void testActionConstraintsAcrossPagesWithoutRefresh() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWTableWebElement wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='0']")).click();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='1']")).click();
    wTableWebElement.getNextPageButton().click();
    driver.waitForPageReady();
    Assert.assertTrue("Select and delete buttons should be enabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled());
    Assert.assertFalse("Edit button should be disabled", driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
    // Needs to be added after ajax/refresh to prevent StaleElementReferenceException
    wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='5']")).click();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='6']")).click();
    Assert.assertFalse("Select button should be enabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
    wTableWebElement.getPreviousPageButton().click();
    driver.waitForPageReady();
    Assert.assertFalse("Select button should be disabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
    wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='0']")).click();
    Assert.assertTrue("Select button should be enabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='0']")).click();
    wTableWebElement.getLastPageButton().click();
    Assert.assertFalse("Select and Edit Buttons should be disabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
    Assert.assertTrue("Delete button should be enabled", driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled());
    driver.clearUserContext();
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWTableWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement) Test(org.junit.Test)

Example 2 with SeleniumWTableWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement in project wcomponents by BorderTech.

the class SimplePaginationTableWithSelectablesExample_Test method testButtonsDisabledOnLoad.

@Test
public void testButtonsDisabledOnLoad() {
    SeleniumWComponentsWebDriver driver = getDriver();
    // List<SeleniumWComponentWebElement> buttons = driver.findElement(byWComponentPath("WButton"));
    Assert.assertFalse("Buttons should be disabled on initial load", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
    SeleniumWTableWebElement wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[role='row']")).click();
    Assert.assertTrue("Buttons should be enabled", driver.findElement(byWComponentPath("WButton[1]")).isEnabled());
    driver.clearUserContext();
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWTableWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement) Test(org.junit.Test)

Example 3 with SeleniumWTableWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement in project wcomponents by BorderTech.

the class SimplePaginationTableWithSelectablesExample_Test method testActionConstraintsAcrossPagesWithRefresh.

@Test
public void testActionConstraintsAcrossPagesWithRefresh() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWTableWebElement wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='0']")).click();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='1']")).click();
    wTableWebElement.getNextPageButton().click();
    driver.waitForPageReady();
    driver.findElement(byWComponentPath(REFRESH_BUTTON)).click();
    Assert.assertTrue("Select and delete buttons should be enabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled());
    Assert.assertFalse("Edit button should be disabled", driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
    // Needs to be added after each refresh to prevent StaleElementReferenceException
    wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='5']")).click();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='6']")).click();
    Assert.assertFalse("Select button should be enabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
    wTableWebElement.getPreviousPageButton().click();
    driver.waitForPageReady();
    driver.findElement(byWComponentPath(REFRESH_BUTTON)).click();
    Assert.assertFalse("Select button should be disabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
    wTableWebElement = getTable();
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='0']")).click();
    Assert.assertTrue("Select button should be enabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
    wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='0']")).click();
    wTableWebElement.getLastPageButton().click();
    driver.findElement(byWComponentPath(REFRESH_BUTTON)).click();
    Assert.assertFalse("Select and Edit Buttons should be disabled", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
    Assert.assertTrue("Delete button should be enabled", driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled());
    driver.clearUserContext();
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWTableWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement) Test(org.junit.Test)

Example 4 with SeleniumWTableWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement in project wcomponents by BorderTech.

the class SimplePaginationTableWithSelectablesExample_Test method testActionConstraintsOnSinglePage.

@Test
public void testActionConstraintsOnSinglePage() {
    SeleniumWComponentsWebDriver driver = getDriver();
    SeleniumWTableWebElement wTableWebElement = getTable();
    for (int i = 0; i < 5; i++) {
        if (i == 0) {
            Assert.assertFalse("Buttons should be disabled when nothing is selected", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
        }
        if (i == 1) {
            Assert.assertTrue("All buttons should be enabled with one item selected", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled() && driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
        }
        if (i > 1) {
            Assert.assertFalse("Edit button should be disabled with more than one item selected", driver.findElement(byWComponentPath(EDIT_BUTTON)).isEnabled());
            Assert.assertTrue("Delete button should be enabled with more than one item selected", driver.findElement(byWComponentPath(DELETE_BUTTON)).isEnabled());
        }
        if ((i > 0) && (i < 4)) {
            Assert.assertTrue("Select button should be enabled with 1 to 3 items selected", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
        }
        if (i >= 4) {
            Assert.assertFalse("Select button should be disabled with 4 or more items selected", driver.findElement(byWComponentPath(SELECT_BUTTON)).isEnabled());
        }
        wTableWebElement.getTable().findElement(By.cssSelector("tr[data-wc-rowindex='" + i + "']")).click();
    }
    driver.clearUserContext();
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) SeleniumWTableWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement) Test(org.junit.Test)

Example 5 with SeleniumWTableWebElement

use of com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement in project wcomponents by BorderTech.

the class SimplePaginationWithRowOptionsTableExample_Test method testPagination.

/**
 * Test the bahviour of a paginated table.
 */
@Test
public void testPagination() {
    SeleniumWTableWebElement table = getTable();
    Assert.assertEquals("Unexpected column header.", "First name", table.getHeaderTextForColumn(0));
    Assert.assertEquals("Unexpected column header.", "Last name", table.getHeaderTextForColumn(1));
    Assert.assertEquals("Unexpected column header.", "DOB", table.getHeaderTextForColumn(2));
    int totalRows = table.getTotalRows();
    int currentPage = table.getCurrentPage();
    int rowsPerPage = table.getRowsPerPage();
    int totalPages = table.getTotalPages();
    Assert.assertEquals("Expected 16 total rows", 16, totalRows);
    Assert.assertEquals("Expected to load first page in table.", 1, currentPage);
    Assert.assertEquals("Expected 2 rows per page by default.", 2, rowsPerPage);
    int expectedTotalPages = (int) Math.floor(totalRows / rowsPerPage);
    Assert.assertEquals("Expected total pages to match.", expectedTotalPages, totalPages);
    Assert.assertEquals("Expected table caption to match", "TABLE CAPTION", table.getTableCaption());
    assertRowContent(table, 0, "Joe", "Bloggs", "01 Feb 1973");
    assertRowContent(table, 1, "Richard", "Starkey", "04 Aug 1976");
    int firstIndex = 1;
    assertPageButtons(table, firstIndex, firstIndex + 1, false, true);
    table.getNextPageButton().click();
    // The table has now been reloaded - have to fetch again.
    table = getTable();
    assertPageButtons(table, firstIndex + rowsPerPage, firstIndex + rowsPerPage + 1, true, true);
    table.getLastPageButton().click();
    // The table has now been reloaded - have to fetch again.
    table = getTable();
    assertPageButtons(table, totalRows - 1, totalRows, true, false);
    table.getPreviousPageButton().click();
    // The table has now been reloaded - have to fetch again.
    table = getTable();
    assertPageButtons(table, (totalRows - rowsPerPage) - 1, totalRows - rowsPerPage, true, true);
}
Also used : SeleniumWTableWebElement(com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement) Test(org.junit.Test)

Aggregations

SeleniumWTableWebElement (com.github.bordertech.wcomponents.test.selenium.element.SeleniumWTableWebElement)5 Test (org.junit.Test)5 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)4