TestNG Error Reporting using Listeners
Testng.xml
<suite
name ="test">
<listeners>
<listener class-name="test.custom_listener"
/>
</listeners>
<test name="test
name">
<classes>
<class
name="test.test_listener"/>
</classes>
</test>
</suite>
custom_listener.java (Listener File)
import
org.testng.ITestResult;
import
org.testng.Reporter;
import
org.testng.TestListenerAdapter;
public class custom_listener extends TestListenerAdapter
{
@Override
public
void onTestFailure(ITestResult
tr) {
Reporter.log(tr.getName()+
"--Test method failed\n");
}
@Override
public
void onTestSkipped(ITestResult
tr) {
Reporter.log(tr.getName()+
"--Test method skipped\n");
}
@Override
public
void onTestSuccess(ITestResult
tr) {
Reporter.log(tr.getName()+
"--Test method success\n");
}
}
Test_listener.java
(Base Class - BaseClass
is the class where my setup(@BeforeClass) and teardown(@AfterClass) method is declared.)
import
org.testng.Assert;
import
org.testng.annotations.Test;
public class test_listener {
@Test //PASS
public
void testMethodOne(){
Assert.assertTrue(true); }
@Test
//FAIL
public void testMethodTwo(){ Assert.assertTrue(false); }
@Test(dependsOnMethods={"testMethodTwo"})
//DEPENDS ON
"testMethodTwo" which will be skipped
public void testMethodThree(){ Assert.assertTrue(true);}
}
Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.
ReplyDeleteWhen I started learning then I understood it has got really cool stuff.
I can vouch webdriver has proved the best feature in
Selenium framework.
thanks a lot for taking a time to share a wonderful article.