title: How to get the test result status from TestNG/Selenium in @AfterMethod?
body: <p>For a research I'm doing, I'm in need of capturing the result status (Passed/Failed) after running the test method (@Test), from @AfterMethod.</p>
  
  <p>I have been using the import org.testng.ITestResult; as an out come of my research to get my work easier after going the several online blogs, but It seems like it didn't success my expectation as always the result outputs as passed, <strong>even though an assertion failed</strong>.</p>
  
  <p>My Code is as follows : </p>
  
  <pre><code>public class SampleTestForTestProject {
  ITestResult result;
  
  @Test(priority = 1)
  public void testcase(){
  
      // intentionally failing the assertion to make the test method fail 
      boolean actual = true;
      boolean expected = false;
      Assert.assertEquals(actual, expected);
  
  }
  
  @AfterMethod
  public void afterMethod()  {
  
      result = Reporter.getCurrentTestResult();
  
      switch (result.getStatus()) {
      case ITestResult.SUCCESS:
          System.out.println("======PASS=====");
          // my expected functionality here when passed
          break;
  
      case ITestResult.FAILURE:
          System.out.println("======FAIL=====");
          // my expected functionality here when passed
          break;
  
      case ITestResult.SKIP:
          System.out.println("======SKIP BLOCKED=====");
          // my expected functionality here when passed
          break;
  
      default:
          throw new RuntimeException("Invalid status");
      }
    }
  }
  </code></pre>
  
  <p>Result in the Console : </p>
  
  <pre><code>[TestNG] Running:  C:\Users\USER\AppData\Local\Temp\testng-eclipse--988445809\testng-customsuite.xml
  
  ======PASS=====
  
  FAILED: testcaseFail
  java.lang.AssertionError: expected [false] but found [true]
  </code></pre>
  
  <p>My expectation is to get the test result to a variable to get through the switch, as given in the above code snippet, and get printed "======FAIL=====" when the test method fail.</p>
  
  <p>Will someone be able assist me kindly to catch the execution test result for each test method (@Test). If the method I have approached is wrong, please assist me with a code snippet to the correct approach, kindly.</p>
  
  <p>Thank you in advance</p>