Class TestNGParameterSource

  • All Implemented Interfaces:
    ConfigSource

    public class TestNGParameterSource
    extends Object
    implements ConfigSource
    Configuration source that provides values from TestNG parameters.

    This source captures parameters from TestNG test execution including:

    • Suite-level parameters (from testng.xml suite)
    • Test-level parameters (from testng.xml test)
    • Method-level parameters (from @Parameters annotation)

    Parameter precedence (highest to lowest):

    1. Method-level parameters
    2. Test-level parameters
    3. Suite-level parameters

    This source is automatically registered when using the TestNGParameterListener which is loaded via TestNG's service loader mechanism.

    Since:
    1.0
    Author:
    Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
    See Also:
    TestNGParameterListener
    • Constructor Detail

      • TestNGParameterSource

        public TestNGParameterSource()
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: ConfigSource
        Returns the name of this configuration source.
        Specified by:
        getName in interface ConfigSource
        Returns:
        the source name, never null
      • get

        public Optional<String> get​(String key)
        Description copied from interface: ConfigSource
        Retrieves a configuration value for the given key.

        If the key is not found in this source, an empty Optional should be returned. This allows the ConfNG system to try other sources in the resolution chain.

        Specified by:
        get in interface ConfigSource
        Parameters:
        key - the configuration key to look up
        Returns:
        an Optional containing the value if found, empty otherwise
      • getPriority

        public int getPriority()
        Description copied from interface: ConfigSource
        Returns the priority of this configuration source.

        Sources with higher priority values are consulted first in the resolution chain. Default priorities:

        • 100+ - Secret managers and secure sources
        • 80-99 - TestNG parameters and test-specific sources
        • 60-79 - Environment variables
        • 40-59 - System properties
        • 20-39 - Configuration files (JSON, Properties)
        • 0-19 - Default and fallback sources
        Specified by:
        getPriority in interface ConfigSource
        Returns:
        the priority value, higher values have higher priority
      • addSuiteParameters

        public void addSuiteParameters​(Map<String,​String> parameters)
        Adds suite-level parameters from TestNG suite configuration.
        Parameters:
        parameters - the suite parameters to add
      • addTestParameters

        public void addTestParameters​(String testName,
                                      Map<String,​String> parameters)
        Adds test-level parameters for a specific test context.
        Parameters:
        testName - the name of the test
        parameters - the test parameters to add
      • addMethodParameters

        public void addMethodParameters​(String methodName,
                                        Map<String,​String> parameters)
        Adds method-level parameters for a specific test method.
        Parameters:
        methodName - the name of the test method
        parameters - the method parameters to add
      • clearSuiteParameters

        public void clearSuiteParameters()
        Clears suite-level parameters.
      • clearTestParameters

        public void clearTestParameters​(String testName)
        Clears test-level parameters for a specific test context.
        Parameters:
        testName - the name of the test to clear parameters for
      • clearMethodParameters

        public void clearMethodParameters​(String methodName)
        Clears method-level parameters for a specific method.
        Parameters:
        methodName - the name of the method to clear parameters for
      • clearAllParameters

        public void clearAllParameters()
        Clears all parameters (suite, test, and method level).
      • getSuiteParameters

        public Map<String,​String> getSuiteParameters()
        Gets all suite parameters.
        Returns:
        a copy of the suite parameters
      • getTestParameters

        public Map<String,​Map<String,​String>> getTestParameters()
        Gets all test parameters for all test contexts.
        Returns:
        a copy of all test parameters
      • getTestParameters

        public Map<String,​String> getTestParameters​(String testName)
        Gets test parameters for a specific test context.
        Parameters:
        testName - the name of the test
        Returns:
        a copy of the test parameters, or empty map if not found
      • getMethodParameters

        public Map<String,​String> getMethodParameters​(String methodName)
        Gets method parameters for a specific method.
        Parameters:
        methodName - the name of the method
        Returns:
        a copy of the method parameters, or empty map if not found
      • getAllParameters

        public Map<String,​String> getAllParameters()
        Gets all parameters in precedence order. Method parameters override test parameters, which override suite parameters.
        Returns:
        a map containing all parameters with proper precedence
      • getCurrentTestName

        public String getCurrentTestName()
        Gets the name of the current test context.
        Returns:
        the current test name, or null if not set
      • setCurrentTestName

        public void setCurrentTestName​(String testName)
        Sets the name of the current test context for the thread.
        Parameters:
        testName - the test name to set as current