-1

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

Assert.assertNotNull(HandleWebTable.printAllHeaderOfWebTable());

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(){
        super();
    }

    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) {
        System.out.println(allRowsName.getText());

    }


}


}
  • 2
    Your code doesn't have any assertion. Could you share the original code, with the assertions and the error message / stacktrace? – João Farias Jul 10 at 8:50
  • I have to use this code to put in assertion: Assert.assertNotNull(HandleWebTable.printAllHeaderOfWebTable()); message: Assert.assertNotNull(HandleWebTable.printAllHeaderOfWebTable( ) is not applicable for the argument void --> same message is coming for all assertion. ... ... – jay Jul 10 at 9:03
  • Please, edit your question with this code - the comment section is pretty unreadable for this kind of text. – João Farias Jul 10 at 9:16
  • I have updated the code, Please have a look and let me know what should be the right approach to assert web table. – jay Jul 10 at 10:13
0

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
Assert.assertFalse(HandleWebTable.printAllHeaderOfWebTable().isEmpty());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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