Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97808

Print the Reporter logs of @BeforeMethod and @AfterMethod in emailable report of testng

$
0
0

I am running some cleanup code in the aftermethod of testng. Everything is smooth but the logs are not printed on the emailable report. But it prints on the console. Is there is any way to print the logs of the before method and after method in the emailable report.html

Providing the sample code

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);
        }
}

Emailable report

I want to integrate somehow the beforemethod and aftermethod logs


Viewing all articles
Browse latest Browse all 97808

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>