Tag Archives: ITestListener

Quick Tip: Selenium – Taking screenshots (of regular tests and test failures)

The What

During Selenium test execution, i want to store a screenshot of what is displayed in the browser to understand in what conditions the test ran.

Continue reading Quick Tip: Selenium – Taking screenshots (of regular tests and test failures)

TestNG custom listeners: ITestListener

When running TestNG tests, one could want to perform some common actions – after each test has finished successfully, after each failed test, after each skipped test, or after all the tests have finished running, no matter their result. To apply such a common behavior to a group of tests, a custom listener can be created, that implements TestNG’s ITestListener interface. There are two types of methods to implement: a set of them are related to a single test’s run (onTestStart, onTestSuccess, onTestFailure, onTestSkipped, onTestFailedButWithinSuccessPercentage), the other to the whole suite’s run (onStart, onFinish). These methods, depending on their type, have a parameter passed to them: result, which is of type ITestResult – for the test run, and context, which is of type ITestContext, for the suite run. These types offer different information, for example: ITestResult can tell you when a test began to run, when it finished running, what status the test had (whether failed, passed), whereas ITestContext can tell you the list of all the passed tests, all the failed ones, and so on.

Continue reading TestNG custom listeners: ITestListener