selenium - 在 testng 的电子邮件报告中打印 @BeforeMethod 和 @AfterMethod 的 Reporter 日志
问题描述
我在 testng 的 aftermethod 中运行了一些清理代码。一切都很顺利,但日志没有打印在可发送电子邮件的报告上。但它打印在控制台上。有没有办法在可发送电子邮件的report.html中打印前方法和后方法的日志
提供示例代码
import java.io.IOException;
import java.lang.reflect.Method;
import org.testng.Reporter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class AutoItTest {
@BeforeMethod(alwaysRun = true)
public void initialize(Method method) {
Reporter.log("Reporter before");
String methodName = method.getName();
int parameterCount = method.getParameterCount();
String className = this.getClass().getCanonicalName();
Reporter.log("methodName: "+methodName);
Reporter.log("parameterCount: "+parameterCount);
Reporter.log("className: "+className);
long threadId = Thread.currentThread().getId();
Reporter.log("threadId before: "+threadId);
Test test = method.getAnnotation(Test.class);
if (test == null) {
return;
}
Reporter.log(test.testName() + " is currently running");
Reporter.log(test.description() + " was its description");
}
@AfterMethod(alwaysRun = true)
public void uninitialize(Method method) {
Reporter.log("Reporter after");
String methodName = method.getName();
int parameterCount = method.getParameterCount();
String className = this.getClass().getCanonicalName();
long threadId = Thread.currentThread().getId();
Reporter.log("threadId after: "+threadId);
Reporter.log("methodName: "+methodName);
Reporter.log("parameterCount: "+parameterCount);
Reporter.log("className: "+className);
}
@Test(groups = "vdi")
public void VDITest() throws IOException, Exception {
Reporter.log("VDITest");
Reporter.log("Reporter VDITest");
long threadId = Thread.currentThread().getId();
Reporter.log("threadId VDITest: "+threadId);
}
@Test(groups = "vdi")
public void VDITest123() throws IOException, Exception {
Reporter.log("VDITest123");
long threadId = Thread.currentThread().getId();
Reporter.log("threadId VDITest123: "+threadId);
}
}
我想以某种方式集成 beforemethod 和 aftermethod 日志
解决方案
我找到了答案
@AfterMethod
public void reportTest(ITestResult result) {
Reporter.setCurrentTestResult(result);
Reporter.log("Message to be printed");
}
我已经添加Reporter.setCurrentTestResult(result);
了@BeforeMethod 和@AfterMethod 以及打印在可发送电子邮件的报告上的连续日志。
推荐阅读
- c++ - 如果尝试清理,由于崩溃而不可避免的 libxml2 内存泄漏
- spring-boot - Spring Boot Show Error with tomcat 8 connection pool打开的文件太多
- arrays - 找不到不同的支持对象'[object Object]
- python - 将字符串转换为熊猫数据框
- python - TypeError:字符串索引必须是使用 pandas 的整数适用于 lambda
- matlab - 如何在 1×41 的向量中生成定位 20 个 -1 值的每个排列?
- ruby-on-rails - Ruby on Rails 中相同模型之间的关系
- c# - HttpWebResponse 提供过期的 cookie
- reactjs - 在本机反应中循环滚动视图
- ruby - 有什么方法可以在 Windows ruby 上搜索特定的注册表项