Search code examples
seleniumselenium-webdrivertestngselenium-idetestng-eclipse

Assertion in selenium webdriver -report showing only falied methods, not passed methods


In my selenium TestNG class, there are some methods, like method1, method2 etc. I have added fail and success conditions to each method.

public class TestNGClass {

public void method1(String value) throws Exception {

  if(value.equals("PASS"){
      org.testng.Assert.assertTrue(condition, message);
  }
}

//This is another method

public void method2(String value) throws Exception {

  if(value.equals("FAIL"){
    org.testng.Assert.fail(message);
  }
}

But after the TestNG class execution, in the Test-Output folder "Index.html" will be created, which shows only the failed methods. How to display the passed methods also (custom report) .?

Thank you

Solution

  • Convert your test methods using @Test annotation. Modified Code Snippet:

    public class TestNGClass {
    
    @Test
    public void method1(){
       Assert.assertTrue(condition, "Your Message goes here");
    }
    
    //This is another method
    @Test
    public void method2(){
      Assert.fail("Your Message goes here");
    }
    

    Now, you will have your testcases reported.