How to get the test result status from TestNG/Selenium in @AfterMethod?

后端 未结 2 1175
一整个雨季
一整个雨季 2021-02-08 00:42

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.

I have been using the im

2条回答
  •  太阳男子
    2021-02-08 01:19

    just do it:

    public class stacktest  {
    
    
    @Test
    public void teststackquestion() {
    
        boolean actual = true;
        boolean expected = false;
       Assert.assertEquals(actual, expected);
    
    }
    
    
    @AfterMethod
    public void afterMethod(ITestResult result)
    {
        try
     {
        if(result.getStatus() == ITestResult.SUCCESS)
        {
    
            //Do something here
            System.out.println("passed **********");
        }
    
        else if(result.getStatus() == ITestResult.FAILURE)
        {
             //Do something here
            System.out.println("Failed ***********");
    
        }
    
         else if(result.getStatus() == ITestResult.SKIP ){
    
            System.out.println("Skiped***********");
    
        }
    }
       catch(Exception e)
       {
         e.printStackTrace();
       }
    
    }
    

    }

提交回复
热议问题