In the previous articles, Design Grid Control Automated Tests Part 1 and Design Grid Control Automated Tests with Java Part 2, I started this mini-series about writing decent grid control automated tests. In this second part, I will talk about how to automate floating-point and date columns.
Design Grid Control’s Paging Tests
We want to design tests about the paging functionality of the grid controls. The available buttons may vary, but the most frequent are- go to the first page, go to last page, go to next page and go to previous page. Of course usually, you can navigate to a specific page by clicking the number of the concrete page. In the example that I will use, there are two additional buttons- next more pages and previous more pages. They load the next or prior batch of pages. I will present to you my opinion about the most appropriate automated tests of these buttons.

Grid Control’s Paging Tests- Arrange Methods
There are two important arrange methods that all tests use for this functionality.
private void initializeInvoicesForPaging() {
var totalOrders = 11;
if (!StringUtils.isEmpty(uniqueShippingName)) {
uniqueShippingName = UUID.randomUUID().toString();
}
testPagingItems = new LinkedList < Order > ();
for (var i = 0; i < totalOrders; i++) {
var newOrder = createNewItemInDb(uniqueShippingName);
testPagingItems.add(newOrder);
}
}
If we assume that our grid control’s paging is set up to use 10-sized paging, we create 11 unique items for every test with an identical unique shipping name. When we change the grid to display one element per page, we will have an item for every page plus an additional one for the more pages buttons.
private void navigateToGridInitialPage(int initialPageNumber) throws Exception {
driver.navigate().to("http://demos.telerik.com/kendo-ui/grid/filter-row");
var kendoGrid = new KendoGrid(driver, driver.findElement(By.id("grid")));
kendoGrid.filter(ShipNameColumnName, FilterOperator.EQUAL_TO, uniqueShippingName);
kendoGrid.changePageSize(1);
waitForGridToLoad(1, kendoGrid);
kendoGrid.navigateToPage(initialPageNumber);
waitForPageToLoad(initialPageNumber, kendoGrid);
assertPagerInfoLabel(initialPageNumber, initialPageNumber, testPagingItems.stream().count());
}
We configure the grid to display only a single item through this method. Also, we navigate to the grid control’s page and a previously specified in the current test case page number. We also apply an EQUAL_TO filter by the unique shipping name of the once created test case 11 elements. We assert the grid control’s paging label at the end of the method.
Go To First Page Button
@Test
public void navigateToFirstPage_GoToFirstPageButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(11);
var targetPage = 1;
var goToFirstPageButton = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[1]"));
goToFirstPageButton.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.get(targetPage - 1).getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
We use the second utility method to navigate to the last 11th page of the grid. Then when we click on the Go To First Page button, we assert that the 1 - 1 of 11 items label is displayed. Additionally, we know which element should be displayed on the first page, so we assert that it is present there.
Go To First Page Button Disabled
@Test
public void goToFirstPageButtonDisabled_WhenFirstPageIsLoaded() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 1;
var goToFirstPageButton = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[1]"));
goToFirstPageButton.click();
waitForPageToLoad(targetPage, kendoGrid);
Assert.assertFalse(goToFirstPageButton.isEnabled());
}
Initially, the test starts on the 11th page, then we navigate to the first page, asserting that the go to first page button is disabled.
Go To Last Page Button
@Test
public void navigateToLastPage_GoToLastPageButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 11;
var goToLastPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[4]/span"));
goToLastPage.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.stream().skip(testPagingItems.stream().count() - 1)
.findFirst().get().getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
The test case loads the first page of the grid. Then it clicks the Go To Last Page button. Then we assert that the expected item is displayed and that the correct paging label is visible.
Go To Last Page Button Disabled
@Test
public void goToLastPageButtonDisabled_WhenLastPageIsLoaded() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 11;
var goToLastPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[4]/span"));
goToLastPage.click();
waitForPageToLoad(targetPage, kendoGrid);
Assert.assertFalse(goToLastPage.isEnabled());
}
Again we start at the first page. Then we navigate to the last 11th page, asserting that the Go To Last Page button is disabled.
Go To Previous Page Button
@Test
public void navigateToPageNine_GoToPreviousPageButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(11);
var targetPage = 10;
var goToPreviousPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[2]/span"));
goToPreviousPage.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.get(targetPage - 1).getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
Here the test starts on page eleven. Then when we click on the Previous Page button, we expect that the 10th page is loaded and the correct item is shown.
Go To Previous Page Button Disabled
@Test
public void goToPreviousPageButtonDisabled_WhenFirstPageIsLoaded() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(11);
var targetPage = 1;
var goToFirstPageButton = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[1]"));
goToFirstPageButton.click();
waitForPageToLoad(targetPage, kendoGrid);
var goToPreviousPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[2]/span"));
Assert.assertFalse(goToPreviousPage.isEnabled());
}
When the first page loads, we assert that the Previous Page button is disabled.
Go To Next Page Button
@Test
public void navigateToPageTwo_GoToNextPageButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 2;
var goToNextPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[3]"));
goToNextPage.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.get(targetPage - 1).getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
The test navigates from page one to two through the Next Page button. In the end, it applies the default asserts.
Go To Next Page Button Disabled
@Test
public void goToNextPageButtonDisabled_WhenLastPageIsLoaded() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 11;
var goToLastPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[4]/span"));
goToLastPage.click();
waitForPageToLoad(targetPage, kendoGrid);
var goToNextPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[3]"));
Assert.assertFalse(goToNextPage.isEnabled());
}
When you are on the last grid page, the test asserts that the Next Page button cannot be clicked.
Next More Pages Button
@Test
public void navigateToLastPage_MorePagesNextButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 11;
var nextMorePages = driver.findElement(By.xpath("//*[@id='grid']/div[3]/ul/li[12]/a"));
nextMorePages.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.get(targetPage - 1).getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
As mentioned earlier, this button skips the following 10 pages. So when we are on the first page and click it, we assert that the grid is on the 11th page.
Next More Pages Button Disabled
@Test
public void nextMorePageButtonDisabled_WhenLastPageIsLoaded() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 11;
var goToLastPage = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[4]/span"));
goToLastPage.click();
waitForPageToLoad(targetPage, kendoGrid);
var previousMorePages = driver.findElement(By.xpath("//*[@id='grid']/div[3]/ul/li[2]/a"));
Assert.assertFalse(previousMorePages.isEnabled());
}
When the last page is reached, the Next More Pages button should be disabled.
Previous More Pages Button
@Test
public void navigateToPageOne_MorePagesPreviousButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 1;
var previousMorePages = driver.findElement(By.xpath("//*[@id='grid']/div[3]/ul/li[2]/a"));
previousMorePages.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.get(targetPage - 1).getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
Analogically, to the previous example, when we load the 11th page and click the Previous More Pages button, we expect that the first page is displayed.
Previous More Pages Button Disabled
@Test
public void previousMorePagesButtonDisabled_WhenFirstPageIsLoaded() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(11);
var targetPage = 1;
var goToFirstPageButton = driver.findElement(By.xpath("//*[@id='grid']/div[3]/a[1]"));
goToFirstPageButton.click();
waitForPageToLoad(targetPage, kendoGrid);
var previousMorePages = driver.findElement(By.xpath("//*[@id='grid']/div[3]/ul/li[2]/a"));
Assert.assertFalse(previousMorePages.isDisplayed());
}
The Previous More Pages button should not be clickable if you are on the first page of the grid.
Number Pages’ Buttons
@Test
public void navigateToPageTwo_SecondPageButton() throws Exception {
initializeInvoicesForPaging();
navigateToGridInitialPage(1);
var targetPage = 2;
var pageOnSecondPositionButton = driver.findElement(By.xpath("//*[@id='grid']/div[3]/ul/li[3]/a"));
pageOnSecondPositionButton.click();
waitForPageToLoad(targetPage, kendoGrid);
List < Order > results = kendoGrid.getItems();
Assert.assertEquals(testPagingItems.get(targetPage - 1).getOrderId(), results.stream().findFirst().get().getOrderId());
assertPagerInfoLabel(targetPage, targetPage, testPagingItems.stream().count());
}
When you click on a numeric button, the test asserts that the page corresponding to that number is loaded.
