[英]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.