Interface ConfNGListener

  • All Known Implementing Classes:
    TestNGParameterListener

    public interface ConfNGListener
    Interface for custom ConfNG listeners that can be executed before or after the standard TestNGParameterListener.

    Implement this interface to add custom logic to the ConfNG listener chain. Listeners are executed in priority order, where lower priority values execute first.

    Priority Guidelines:

    • Negative numbers: Pre-processing listeners (execute before TestNGParameterListener)
    • 0: TestNGParameterListener (default ConfNG listener)
    • Positive numbers: Post-processing listeners (execute after TestNGParameterListener)

    Example Usage:

     public class CustomPreListener implements ConfNGListener {
         @Override
         public int getPriority() {
             return -10; // Execute before TestNGParameterListener (negative priority)
         }
    
         @Override
         public void onSuiteStart(ISuite suite) {
             System.out.println("Custom pre-processing before ConfNG loads config");
             // Your custom logic here
         }
     }
    
     public class CustomPostListener implements ConfNGListener {
         @Override
         public int getPriority() {
             return 10; // Execute after TestNGParameterListener (positive priority)
         }
    
         @Override
         public void onSuiteStart(ISuite suite) {
             System.out.println("Custom post-processing after ConfNG loads config");
             // Your custom logic here
         }
     }
     

    Registration:

    Register your listener using Java's ServiceLoader mechanism by creating a file:

     META-INF/services/org.confng.testng.ConfNGListener
     

    Add your listener class name(s) to this file:

     com.example.CustomPreListener
     com.example.CustomPostListener
     
    Since:
    1.0.3
    Author:
    Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
    See Also:
    TestNGListenerChain, TestNGParameterListener
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void afterInvocation​(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)
      Called after a method is invoked (IInvokedMethodListener).
      default void afterMethodInvocation​(org.testng.ITestContext testContext, String methodName)
      Called after a method is invoked (simplified version for convenience).
      default void beforeInvocation​(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)
      Called before a method is invoked (IInvokedMethodListener).
      default void beforeMethodInvocation​(org.testng.ITestContext testContext, String methodName)
      Called before a method is invoked (simplified version for convenience).
      int getPriority()
      Returns the priority of this listener.
      default void onFinish​(org.testng.ITestContext context)
      Called when a test context finishes (ITestListener).
      default void onStart​(org.testng.ITestContext context)
      Called when a test context starts (ITestListener).
      default void onSuiteFinish​(org.testng.ISuite suite)
      Called when a test suite finishes.
      default void onSuiteStart​(org.testng.ISuite suite)
      Called when a test suite starts.
      default void onTestFailedButWithinSuccessPercentage​(org.testng.ITestResult result)
      Called when a test fails but is within the success percentage.
      default void onTestFailedWithTimeout​(org.testng.ITestResult result)
      Called when a test fails with timeout.
      default void onTestFailure​(org.testng.ITestResult result)
      Called when a test fails.
      default void onTestSkipped​(org.testng.ITestResult result)
      Called when a test is skipped.
      default void onTestStart​(org.testng.ITestResult result)
      Called when a test starts.
      default void onTestSuccess​(org.testng.ITestResult result)
      Called when a test succeeds.
    • Method Detail

      • getPriority

        int getPriority()
        Returns the priority of this listener. Lower values execute first.

        Priority ranges:

        • Negative numbers: Pre-processing (before TestNGParameterListener)
        • 0: TestNGParameterListener (default)
        • Positive numbers: Post-processing (after TestNGParameterListener)
        Returns:
        the priority value (can be negative, zero, or positive)
      • onSuiteStart

        default void onSuiteStart​(org.testng.ISuite suite)
        Called when a test suite starts.
        Parameters:
        suite - the test suite
      • onSuiteFinish

        default void onSuiteFinish​(org.testng.ISuite suite)
        Called when a test suite finishes.
        Parameters:
        suite - the test suite
      • onTestStart

        default void onTestStart​(org.testng.ITestResult result)
        Called when a test starts.
        Parameters:
        result - the test result
      • onTestSuccess

        default void onTestSuccess​(org.testng.ITestResult result)
        Called when a test succeeds.
        Parameters:
        result - the test result
      • onTestFailure

        default void onTestFailure​(org.testng.ITestResult result)
        Called when a test fails.
        Parameters:
        result - the test result
      • onTestSkipped

        default void onTestSkipped​(org.testng.ITestResult result)
        Called when a test is skipped.
        Parameters:
        result - the test result
      • onTestFailedButWithinSuccessPercentage

        default void onTestFailedButWithinSuccessPercentage​(org.testng.ITestResult result)
        Called when a test fails but is within the success percentage.
        Parameters:
        result - the test result
      • onTestFailedWithTimeout

        default void onTestFailedWithTimeout​(org.testng.ITestResult result)
        Called when a test fails with timeout.
        Parameters:
        result - the test result
      • onStart

        default void onStart​(org.testng.ITestContext context)
        Called when a test context starts (ITestListener).
        Parameters:
        context - the test context
      • onFinish

        default void onFinish​(org.testng.ITestContext context)
        Called when a test context finishes (ITestListener).
        Parameters:
        context - the test context
      • beforeInvocation

        default void beforeInvocation​(org.testng.IInvokedMethod method,
                                      org.testng.ITestResult testResult)
        Called before a method is invoked (IInvokedMethodListener).
        Parameters:
        method - the invoked method
        testResult - the test result
      • afterInvocation

        default void afterInvocation​(org.testng.IInvokedMethod method,
                                     org.testng.ITestResult testResult)
        Called after a method is invoked (IInvokedMethodListener).
        Parameters:
        method - the invoked method
        testResult - the test result
      • beforeMethodInvocation

        default void beforeMethodInvocation​(org.testng.ITestContext testContext,
                                            String methodName)
        Called before a method is invoked (simplified version for convenience).
        Parameters:
        testContext - the test context
        methodName - the method name
      • afterMethodInvocation

        default void afterMethodInvocation​(org.testng.ITestContext testContext,
                                           String methodName)
        Called after a method is invoked (simplified version for convenience).
        Parameters:
        testContext - the test context
        methodName - the method name