-1

I have a method where i have taken the rowcount of 10 records on page load and 15 records after changing the page no to 15 question here is how to validate by creating a Assert method seperatly in order to validate the count

Below is my method:

    public void pagenation()
{

    List<WebElement> noofrowbefore = driver.findElements(By.xpath("//table/tbody/tr/td[1]/p"));
    int beforecount = noofrowbefore.size();
    for(int i=0;i<noofrowbefore.size();i++)
        JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("window.scrollBy(0,2500)");

    elementInteraction.onClick(pagedropdown);
    wait.until(ExpectedConditions.visibilityOfElementLocated(pagenumberselection));
    elementInteraction.onClick(pagenumberselection);
  //after selecting  the pagenumber need to validate the number of records in the grid
    List<WebElement> noofrowAfter = driver.findElements(By.xpath("//table/tbody/tr/td[1]/p"));
    int aftercount = noofrowAfter.size();
}

Any inputs..

2
  • Hi. Pardon if it sounds rude, but the question is difficult to understand grammarly. I would suggest explaining succinctly your context, your goal, what you tried to do, what your results were, and what are your questions - each part in one paragraph/sentence and referencing your code's elements. May 11 at 17:11
  • Agree but got a solution to this thanks @JoãoFarias
    – user56056
    May 12 at 2:02

1 Answer 1

0

To validate the count of records before and after changing the page number, you can create a separate Assert method. Here's an example of how you can modify your code to include the Assert method:

import org.testng.Assert;

public void pagination() {
    List<WebElement> noOfRowsBefore = driver.findElements(By.xpath("//table/tbody/tr/td[1]/p"));
    int beforeCount = noOfRowsBefore.size();

    // Scroll down the page
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.scrollBy(0,2500)");

    elementInteraction.onClick(pagedropdown);
    wait.until(ExpectedConditions.visibilityOfElementLocated(pagenumberselection));
    elementInteraction.onClick(pagenumberselection);

    // Wait for the page to load with new records
    // Add necessary wait condition here if required

    List<WebElement> noOfRowsAfter = driver.findElements(By.xpath("//table/tbody/tr/td[1]/p"));
    int afterCount = noOfRowsAfter.size();

    // Assertion
    Assert.assertEquals(afterCount, beforeCount + 5, "Number of records is not as expected after changing the page number.");
}

In this example, I have used the assertEquals method from TestNG's Assert class to compare the count of records before and after changing the page number. The expected count after changing the page number is beforeCount + 5, assuming each page displays 5 records.

You can customize the assertion according to your specific requirement. If the count doesn't match, the assertion will throw an assertion error with the provided message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.