ローマボストニアン:
私は、エクステントレポートライブラリ(バージョン4)を使用して、我々のテストフレームワークに、HTMLレポートを統合しています。
その目的のために、私は、(HTML-レポートの収集データにExtentTest.log、)(コンソール出力のために)私たちのデフォルトのTestNGロガーをカプセル化するラッパー、およびExtentReportロガーを書きました。私たちは、テストフレームワークとしてTestNGのを使用しています。
HTML - レポートに表示することができなかったアサーション(ソフトとハードの両方のアサーション)からのログメッセージをキャプチャする問題を持って、彼らは、コンソールログにだけ行きます。HTML-レポートでそれらを表示し、それらのアサートログメッセージをキャプチャするために可能な解決策は何でしょうか?
私はアサート(またはSoftAssert)クラスを拡張して、私はテストの数十のすべてのアサーションを交換する必要があると思いますので、(そこExtentTest.logのインスタンスを追加することで)私自身の実装を追加することはできません。
public class Loggers {
private static final Loggers instance = new Loggers();
private static ExtentTest test;
private static ExtentReports extent;
private static Logger LOG;
private static final String REPORT_LOCATION = "test-output/reports.extent.html";
/**
* Returns an instance of {@link ExtentReports} object. If it doesn't exist creates a new instance and returns it
*/
public static ExtentReports getLogger() {
if ( extent == null ) {
createInstance();
}
return extent;
}
/**
* Create ExtentReport and attaches htmlReporter to it
*/
public static void createInstance() {
ExtentHtmlReporter htmlReporter = getHTMLReporter();
extent = new ExtentReports();
extent.attachReporter( htmlReporter );
}
/**
* This method creates, configures and returns an instance of ExtentHtmlReporter
*
*/
public static ExtentHtmlReporter getHTMLReporter() {
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter( REPORT_LOCATION );
return htmlReporter;
}
/**
* This method logs a message with the INFO level for both instances of TestNG Logger and ExtentTest
*/
public void info( String message ) {
LOG.info( message );
test.log( Status.INFO, message );
}
ローマボストニアン:
解決策を見つけました。誰かが同様の問題を持っているかどうここに掲載します。
あなたがリスナークラスであなたのロガーを見つけた場合は、特にその方法getThrowableが(それはメソッドを実行中にスローされたThrowableオブジェクトを返します)、そこの上にロガーを入れて、引数としてITestResultを使用することができます
/**
* Triggered upon the failure of a test
*/
public void onTestFailure( ITestResult testResult ) {
LOG.fail( testResult.getThrowable() );
}
これは、レポートに失敗したアサーションやスローされた例外を出力します。