如何抑制在selenium中的testng报告中显示的AssertionError

时间:2013-02-01 09:36:57

标签: selenium testng

我在控制台和报告中也收到以下错误。但我不希望在报告中显示此错误跟踪。如何抑制报告中显示的此错误? 我用自定义失败消息调用此函数Library.Test(): 我的代码是:

AssertJUnit.assertTrue("FAIL: Please check the logs in report. Either there are no more than 10 records and there is a problem in application.",Library.Test());  

我的AssertionError跟踪如下:

FAILED: TC
java.lang.AssertionError: FAIL: Please check the logs in report. Either there are no more than 10 records and there is a problem in application.
  at org.testng.AssertJUnit.fail(AssertJUnit.java:59)
  at org.testng.AssertJUnit.assertTrue(AssertJUnit.java:24)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
  at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
  at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
  at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
  at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
  at org.testng.TestRunner.privateRun(TestRunner.java:767)
  at org.testng.TestRunner.run(TestRunner.java:617)
  at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
  at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
  at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
  at org.testng.SuiteRunner.run(SuiteRunner.java:240)
  at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
  at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
  at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
  at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
  at org.testng.TestNG.run(TestNG.java:1036)
  at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
  at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
  at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

1 个答案:

答案 0 :(得分:1)

我发现直到现在似乎无法通过XML文件配置记者。

现在,只有将-reporter命令行参数传递给TestNG才能实现这一点:

-reporter org.testng.reporters.XMLReporter:stackTraceOutputMethod=0[,additional=param]

可以在TestNG Logger Config documentation中找到接受的参数。

默认情况下,它会输出完整的堆栈跟踪,但您可以在报告中配置任何长度的堆栈跟踪。 将配置参数“stackTraceOutputMethod”设置为0将仅输出Exception类和消息,这听起来像您正在寻找的bevahior。

如果您需要更多地调整报告,可以查看Reporter API