What should be Assert for below code, tried for assertTrue,assertFalse,assertNull and assertNotNull

  • I have written below code to verify web table data headers and value of rows and columns but when I am adding different assertion for it, its not working and throwing compilation error. Can any one help me on this, my most of the test cases depend on this.

    I have to use this code to put in assertion: Tried with below assertion


    Error message: Assert.assertNotNull(HandleWebTable.printAllHeaderOfWebTable( ) is not applicable for the argument void --> same message is coming for all assertion.

    package com.deere.gmsr.utility;
    import java.util.List;
    import java.util.ListIterator;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import com.deere.gmsr.driver.Driver;
    public class HandleWebTable {
        private static WebDriver driver;
        public HandleWebTable(){
        public static void printAllHeaderOfWebTable() {
        List<WebElement> allHeaderTable=driver.findElements(By.xpath("//div[@class='panel history-panel panel panel-default']"));
        int allHeaderSize=allHeaderTable.size();
        ListIterator<WebElement> tr=allHeaderTable.listIterator();
        System.out.println("Traverse in forwrd direction");
        while(tr.hasNext()) {
            System.out.println("index" + tr.nextIndex() + "value" + tr.next());
        List<WebElement> allHeaderTable1=driver.findElements(By.xpath("//div[@class='panel history-panel panel panel-default']"));
        int allHeaderSize1=allHeaderTable1.size();
        List<WebElement> allRows=driver.findElements(By.xpath("//*[section/div[1]/div[3]/div/div[2]/div/div/div[1]/div/table/thead/tr/th[1]]"));
        for(WebElement allRowsName:allRows) {

  • The method printAllHeaderOfWebTable returns nothing (void).

    In Java, it doesn't mean that it returns null.

    What you can do it to return the list of rows and check if there are any row:

    public static List<WebElement> printAllHeaderOfWebTable() {
       /// ...
       return allRows;
    // It will pass if the list is not empty

Suggested Topics