У меня возникла проблема с файлом ExtentReports. html, указав, что это недопустимый файл экстента.
Прослушиватель TestNG по умолчанию используется для создания отчетов по экстентам. Как указано в других вопросах, я добавил reports.flush()
в onFinish(ITestContext context)
метод, который выполняется после всех методов @Test.
Эта проблема возникает в следующей строке:
public class TestListener implements ITestListener {
public ExtentReports reports;
public void onStart(ITestContext context) {
/** this is where the error is thrown **/
reports = new ExtentReports(dir + "/ExtentReportTestNG.html", false, DisplayOrder.OLDEST_FIRST);
reports.loadConfig(new File(System.getProperty("user.dir") + "/extent-config.xml"));
}
}
На самом деле Могу сказать, что это серьезное предупреждение:
SEVERE: The supplied file C:\Bala\E\Checkouts\seleniumScriptsRegression\test-output\ExtentReportTestNG.html is not a valid Extent file. Parsing failed, tests from the supplied file will not be listed in the current report.
Это предупреждение влияет на следующую строку кода:
public void onFinish(ITestContext context) {
try {
reports.endTest(test);
reports.flush(); //The error line
}
}
Ниже приведена полная трассировка стека исключения NullPointerException:
FreeMarker template error:
The following has evaluated to null or missing:
==> report.systemInfoMap[info] [in template "Extent.ftl" at line 193, column 95]
----
Tip: It's the final [] step that caused this error, not those before it.
----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${report.systemInfoMap[info]} [in template "Extent.ftl" at line 193, column 93]
----
Java stack trace (for programmers):
----
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:131)
at freemarker.core.EvalUtil.coerceModelToString(EvalUtil.java:355)
at freemarker.core.Expression.evalAndCoerceToString(Expression.java:82)
at freemarker.core.DollarVariable.accept(DollarVariable.java:41)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
at freemarker.core.IteratorBlock$IterationContext.executeNestedBlockInner(IteratorBlock.java:240)
at freemarker.core.IteratorBlock$IterationContext.executeNestedBlock(IteratorBlock.java:220)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:194)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:572)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:78)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:64)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.Environment.process(Environment.java:302)
at freemarker.template.Template.process(Template.java:325)
at com.relevantcodes.extentreports.HTMLReporter.flush(HTMLReporter.java:173)
at com.relevantcodes.extentreports.Report.flush(Report.java:468)
at com.relevantcodes.extentreports.ExtentReports.flush(ExtentReports.java:900)
at com.exterro.fusion.selenium.controls.TestListener.onFinish(TestListener.java:195)
at org.testng.TestRunner.fireEvent(TestRunner.java:1239)
at org.testng.TestRunner.afterRun(TestRunner.java:1030)
at org.testng.TestRunner.run(TestRunner.java:636)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
java.lang.NullPointerException
at java.io.Writer.write(Unknown Source)
at com.relevantcodes.extentreports.utils.Writer.write(Writer.java:21)
at com.relevantcodes.extentreports.HTMLReporter.flush(HTMLReporter.java:186)
at com.relevantcodes.extentreports.Report.flush(Report.java:468)
at com.relevantcodes.extentreports.ExtentReports.flush(ExtentReports.java:900)
at com.exterro.fusion.selenium.controls.TestListener.onFinish(TestListener.java:195)
at org.testng.TestRunner.fireEvent(TestRunner.java:1239)
at org.testng.TestRunner.afterRun(TestRunner.java:1030)
at org.testng.TestRunner.run(TestRunner.java:636)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)