【问题标题】:Print the Reporter logs of @BeforeMethod and @AfterMethod in emailable report of testng在 testng 的电子邮件报告中打印 @BeforeMethod 和 @AfterMethod 的 Reporter 日志
【发布时间】: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


    【解决方案1】:

    我找到了答案

    @AfterMethod
    public void reportTest(ITestResult result) {
      Reporter.setCurrentTestResult(result);
      Reporter.log("Message to be printed");
    }
    

    我在@BeforeMethod 和@AfterMethod 中都添加了Reporter.setCurrentTestResult(result);,并在可发送电子邮件的报告上打印了连续的日志。

    【讨论】:

      猜你喜欢
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多