TestNGの@afterメソッドでは、スタックトレースをキャプチャしてエクステントレポートに含めたいと思っていますが、良い解決策を見つけることができません。私は、スタックトレースを印刷する上で、たくさんのスレッドがあることを認識していますが、私が望むものを私に与えているものはありません。私は、失敗の原因となったメソッドと行番号が必要です。私はスタックトレースが巨大であるかどうか気にしません。なぜなら、失敗した行までのリードを見たいと思うからです。ここで TestNGの@afterメソッドからエクステントレポートにスタックトレースを書き込む
は、私はエクステントレポートに書き込む場所の例です:@AfterMethod(alwaysRun = true)
public void afterMethod(ITestResult result, Method method) throws InterruptedException {
ExtentTest test = ExtentTestManager.getTest();
// Get thread id
long id = Thread.currentThread().getId();
if (result.getStatus() != ITestResult.SKIP)
{
String os = StoredVariables.getos().get();
String resultStatus = "";
// Write passing tests to Extent Reports
if (result.getStatus() == ITestResult.SUCCESS) {
test.log(LogStatus.PASS, "<span class='label success'>" + result.getName() + "</span>");
resultStatus = "Passed";
StoredVariables.getfailedTest().set(false);
}
// Write failing tests to Extent Reports
if (result.getStatus() == ITestResult.FAILURE) {
test.log(LogStatus.FAIL, "<span class='label failure'>" + result.getName() + "</span>", "<pre>Results = " + result.getThrowable().getCause() + "\n\n" + result.getThrowable().getMessage() + "</pre>");
resultStatus = "Failed";
StoredVariables.getfailedTest().set(true);
}
System.out.println("TEST RESULT: " + method.getName() + " - Thread " + id + " = " + resultStatus);
Thread.currentThread().getStackTrace()
は私を与える "[Ljava.lang.StackTraceElement; 2e1ef60 @"
印刷ItestResult result
が直接近づく私を取得しますから
[TestResult name=functionChecks status=FAILURE method=ExampleScripts.functionChecks()[pri:0, instance:[email protected]] output=Completed executing following method : ExampleScripts.functionChecks]
result.getThrowable()を使用すると、 "java.lang.AssertionError:Failed expected [true]が見つかりましたが、[false]"が表示されます。まだ行番号がなく、私は失敗の原因をキャプチャしようとしていますが、必ずしも最後のメソッド呼び出し –
@DustinNとは限りません。 Hei。私は同じresult.getThrowable()を使用しており、ExtentReportsログに完全なスタックトレースを取得しています。どの程度のレポートバージョンを使用していますか? –
私はExtent Reportsバージョン2.41.0とSelenium 2.53.0を使用しています。 –