Good morning!
I'm having a heck of a time getting iSuiteListener to work with Log4J2. Works perfectly with iTestListener, but not for suite. The *only* change to running is changing the test listener in the xml, zero other code changes. First, here are the two xml portions (NOTE: The two Listener java files are at the end:
testlistener:
<listeners>
<listener class-name="tests.TestListener" />
</listeners>
suitelistener:
<listeners>
<listener class-name="tests.SuiteListener" />
</listeners>
If I use the TestListener, Everything works fine, and I get the following in the log file (Note "
FileAppender$Builder(fileName="
:
[RemoteTestNG] detected TestNG version 6.14.3
2018-06-08 08:43:33,855 main DEBUG Initializing configuration XmlConfiguration[location=jar:file:/C:/Users/gmartz/.m2/repository/com/costco/ebusiness/test-automation-framework/1.0.33/test-automation-framework-1.0.33.jar!/log4j2.xml]
2018-06-08 08:43:33,855 main DEBUG Installed 2 script engines
2018-06-08 08:43:33,914 main DEBUG BeanShell Engine version: 1.0, language: BeanShell, threading: MULTITHREADED, compile: true, names: [beanshell, bsh, java], factory class: bsh.engine.BshScriptEngineFactory
2018-06-08 08:43:34,149 main DEBUG Oracle Nashorn version: 1.8.0_172, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-06-08 08:43:34,149 main DEBUG PluginManager 'Core' found 116 plugins
2018-06-08 08:43:34,149 main DEBUG PluginManager 'Level' found 0 plugins
2018-06-08 08:43:34,165 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-06-08 08:43:34,165 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2018-06-08 08:43:34,165 main DEBUG PluginManager 'TypeConverter' found 26 plugins
2018-06-08 08:43:34,181 main DEBUG PatternLayout$Builder(pattern="%d{MM-dd-yyyy HH:mm:ss} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(jar:file:/C:/Users/gmartz/.m2/repository/com/costco/ebusiness/test-automation-framework/1.0.33/test-automation-framework-1.0.33.jar!/log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
2018-06-08 08:43:34,181 main DEBUG PluginManager 'Converter' found 44 plugins
2018-06-08 08:43:34,196 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.FileAppender].
2018-06-08 08:43:34,212 main DEBUG FileAppender$Builder(fileName="C:\workdir\ecom-bc\test-output\OrderStatusDetailDisplayOneRowPerOrderItemUS_29391_TestSuite.log", append="true", locking="null", advertise="null", advertiseUri="null", createOnDemand="null", filePermissions="null", fileOwner="null", fileGroup="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{MM-dd-yyyy HH:mm:ss} [%t] %-5level %logger{36} - %msg%n), name="FILE", Configuration(jar:file:/C:/Users/gmartz/.m2/repository/com/costco/ebusiness/test-automation-framework/1.0.33/test-automation-framework-1.0.33.jar!/log4j2.xml), Filter=null)
Changing the same xml to the SuiteListener, and I get the following in the log:
[RemoteTestNG] detected TestNG version 6.14.3
2018-06-08 08:44:59,188 main DEBUG Initializing configuration XmlConfiguration[location=jar:file:/C:/Users/gmartz/.m2/repository/com/costco/ebusiness/test-automation-framework/1.0.33/test-automation-framework-1.0.33.jar!/log4j2.xml]
2018-06-08 08:44:59,188 main DEBUG Installed 2 script engines
2018-06-08 08:44:59,486 main DEBUG Oracle Nashorn version: 1.8.0_172, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-06-08 08:44:59,533 main DEBUG BeanShell Engine version: 1.0, language: BeanShell, threading: MULTITHREADED, compile: true, names: [beanshell, bsh, java], factory class: bsh.engine.BshScriptEngineFactory
2018-06-08 08:44:59,533 main DEBUG PluginManager 'Core' found 116 plugins
2018-06-08 08:44:59,533 main DEBUG PluginManager 'Level' found 0 plugins
2018-06-08 08:44:59,549 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-06-08 08:44:59,549 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2018-06-08 08:44:59,564 main DEBUG PluginManager 'TypeConverter' found 26 plugins
2018-06-08 08:44:59,564 main DEBUG PatternLayout$Builder(pattern="%d{MM-dd-yyyy HH:mm:ss} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(jar:file:/C:/Users/gmartz/.m2/repository/com/costco/ebusiness/test-automation-framework/1.0.33/test-automation-framework-1.0.33.jar!/log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
2018-06-08 08:44:59,564 main DEBUG PluginManager 'Converter' found 44 plugins
2018-06-08 08:44:59,580 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.FileAppender].
2018-06-08 08:44:59,595 main DEBUG FileAppender$Builder(fileName="${sys:logFilename}", append="true", locking="null", advertise="null", advertiseUri="null", createOnDemand="null", filePermissions="null", fileOwner="null", fileGroup="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{MM-dd-yyyy HH:mm:ss} [%t] %-5level %logger{36} - %msg%n), name="FILE", Configuration(jar:file:/C:/Users/gmartz/.m2/repository/com/costco/ebusiness/test-automation-framework/1.0.33/test-automation-framework-1.0.33.jar!/log4j2.xml), Filter=null)
2018-06-08 08:44:59,595 main ERROR FileManager (${sys:logFilename}) java.io.IOException: The filename, directory name, or volume label syntax is incorrect java.io.IOException: The filename, directory name, or volume label syntax is incorrect
Here is the TestListener.java:
package tests;
import java.util.Iterator;
import framework.Log;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
public class TestListener implements ITestListener
{
// This belongs to ITestListener and will execute before starting of Test set/batch
@Override
public void onStart(ITestContext arg0)
{
Log.info("**********About to begin executing Test " + arg0.getName());
}
// This belongs to ITestListener and will execute, once the Test set/batch is finished
@Override
public void onFinish(ITestContext arg0)
{
Log.info("**********Completed executing test " + arg0.getName());
Iterator<ITestResult> listOfFailedTests = arg0.getFailedTests().getAllResults().iterator();
while (listOfFailedTests.hasNext())
{
ITestResult failedTest = listOfFailedTests.next();
ITestNGMethod method = failedTest.getMethod();
if (arg0.getFailedTests().getResults(method).size() > 1)
{
listOfFailedTests.remove();
}
else
{
if (arg0.getPassedTests().getResults(method).size() > 0)
{
listOfFailedTests.remove();
}
}
}
}
// This belongs to ITestListener and will execute only when the test is pass
@Override
public void onTestSuccess(ITestResult arg0)
{
// This is calling the printTestResults method
printTestResults(arg0);
}
// This belongs to ITestListener and will execute only on the event of fail test
@Override
public void onTestFailure(ITestResult arg0)
{
// This is calling the printTestResults method
printTestResults(arg0);
}
// This belongs to ITestListener and will execute before the main test start (@Test)
@Override
public void onTestStart(ITestResult arg0)
{
Log.info("**********The execution of the main test starts now");
}
// This belongs to ITestListener and will execute only if any of the main test(@Test) get skipped
@Override
public void onTestSkipped(ITestResult arg0)
{
printTestResults(arg0);
}
// Ignore this
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0)
{
}
// This is the method which will be executed in case of test pass or fail
// This will provide the information on the test
private void printTestResults(ITestResult result)
{
Log.info("**********Test Method resides in " + result.getTestClass().getName());
if (result.getParameters().length != 0)
{
String params = null;
for (Object parameter : result.getParameters())
{
params += parameter.toString() + ",";
}
Log.info("**********Test Method had the following parameters : " + params);
}
String status = null;
switch (result.getStatus())
{
case ITestResult.SUCCESS:
{
status = "Pass";
break;
}
case ITestResult.FAILURE:
{
status = "Failed";
break;
}
case ITestResult.SKIP:
{
status = "Skipped";
}
}
Log.info("**********Test Status: " + status);
}
}
Here is the SuiteListener.java:
package tests;
import framework.Log;
import org.testng.ISuite;
import org.testng.ISuiteListener;
public class SuiteListener implements ISuiteListener
{
// This belongs to ISuiteListener and will execute before the Suite start
@Override
public void onStart(ISuite arg0)
{
Log.info("**********About to begin executing Suite " + arg0.getName());
}
// This belongs to ISuiteListener and will execute, once the Suite is finished
@Override
public void onFinish(ISuite arg0)
{
Log.info("**********About to end executing Suite " + arg0.getName());
}
}
Thanks!
Greg
Greg MartzTest Analyst III - eBusiness Lead QA Automation Analyst | (425)416-5039 | gma...@Costco.com
"Confidentiality Notice: This e-mail message, including any attachments, is for the sole use to the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message."