【发布时间】:2020-02-21 15:38:14
【问题描述】:
我在 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 日志
【问题讨论】:
标签: selenium selenium-webdriver junit webdriver testng