Search code examples
javaseleniummaventestngmaven-surefire-plugin

How to print exceptions on console? I am using TestNG and Maven


I want to see the exceptions on console. I am using TestNG with Maven as a build tool. I have defined my testng.xml in the Maven surefire plugin.


Solution

  • https://www.javadoc.io/doc/org.testng/testng/latest/org/testng/reporters/VerboseReporter.html

    you should use above reporter , but the constructor expects a string so you cannot initialize it using testng.xml ( if any one knows how to pass string argument to listener in testng.xml please do add it here )

    So the work around is to add the listener through script and initiate testng through a java entry file.

    public static void main(String[] args) {
    
    
            TestNG testng = new TestNG();
    
            // Create a list of String
            List<String> suitefiles = new ArrayList<String>();
    
            // Add xml file which you have to execute
            suitefiles.add(prop.getProperty("path_to_your_existing_testngxml\testng.xml"));
    
            // now set xml file for execution
            testng.setTestSuites(suitefiles);
            
            testng.addListener(new VerboseReporter("[TestNG] "));
    
            // finally execute the runner using run method
            testng.run();
    
    }
    

    Output:

    enter image description here

    Note

    As this reporter constructor expects a string you should not provide it in your testng.xml you will get initialization error