Design Grid Control Automated Tests with Java Part 3

Design Grid Control Automated Tests with Java Part 3

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.

Design Grid Control Tests Paging

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.

Related Articles

Java, Web Automation Java

Automate Telerik Kendo Grid with WebDriver with Java and JavaScript

Have you had this problem trying to automate custom-tuned web controls? Probably, your team has purchased these from some dedicated UI controls vendor. There ar

Automate Telerik Kendo Grid with WebDriver with Java and JavaScript

Web Automation Java

Playwright Tutorial: IFrame and Shadow DOM Automation

In this post, we will go through the basics of IFrames and Shadow DOM, and we will learn the strategies of automating these complex HTML structures with Playwri

Playwright Tutorial: IFrame and Shadow DOM Automation

Web Automation Java

Playwright Tutorial: Exploring Test Automation with Java

Playwright, developed by Microsoft and launched in early 2020, is a powerful framework for web testing and automation. It offers a range of benefits:

Playwright Tutorial: Exploring Test Automation with Java

Web Automation Java

Deep Dive into JUnit Assertions with WebDriver and Custom Assertions

JUnit assertions are a cornerstone of Java testing, enabling developers to write tests that verify code behavior. In this article, we'll explore the various JUn

Deep Dive into JUnit Assertions with WebDriver and Custom Assertions

Java, Web Automation Java

Selenium WebDriver Tor Network Integration Java Code

For a long time, I wanted to write automation using the Tor Web Browser. My preferred automation framework is Selenium WebDriver. However, I found out that ther

Selenium WebDriver Tor Network Integration Java Code

Java, Web Automation Java

30 Advanced WebDriver Tips and Tricks Java Code

This is the next article from the WebDriver Series where I will share with you 30 advanced tips and tricks using Java code. I wrote similar articles separated i

30 Advanced WebDriver Tips and Tricks Java Code
Anton Angelov

About the author

Anton Angelov is Managing Director, Co-Founder, and Chief Test Automation Architect at Automate The Planet — a boutique consulting firm specializing in AI-augmented test automation strategy, implementation, and enablement. He is the creator of BELLATRIX, a cross-platform framework for web, mobile, desktop, and API testing, and the author of 8 bestselling books on test automation. A speaker at 60+ international conferences and researcher in AI-driven testing and LLM-based automation, he has been recognized as QA of the Decade and Webit Changemaker 2025.