[英]How to access test-output directory that Reporter uses from ITestListener
我們正在使用IReporter的generateReport()方法創建自定義報告。 在運行開始時,我們需要刪除報告文件(如果存在)。
之所以需要這樣做,是因為我們在ITestListener的onStart()方法中利用了SkipException-如果引發某些異常,我們需要使測試運行失敗/停止。 如果發生這種情況,則永遠不會調用generateReport(),而將現有的自定義報告保留在原處,通常會造成混亂。
如何從ITestListener訪問generateReport()中使用的同一outputDirectory? 我可以獲取ITestContext的outputDirectory,但這將我帶到Reporter的outputDirectory的子文件夾。
public class CustomTestListener implements ITestListener {
@Override
public void onStart(ITestContext ctx) {
// This returns a child directory of the actual directory we want
// String outputDir = ctx.getOutputDirectory();
// This is null, how would i access from ITestContext?
// XMLReporter x = new XMLReporter();
// String outputDir = x.getOutputDirectory();
// method that would delete the file
String reportFile = outputDir + "/" + GlobalConstants.REPORT_FILE;
deleteFile (reportFile);
}
}
我想出了一個解決方案,這對我有用:
String outputDir = ctx.getOutputDirectory() + "/../"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.