Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Extent Report in Selenium

import java.io.File;
import java.lang.reflect.Method;

import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;


public class ExtentReport {

ExtentReports reports;
ExtentTest testlog;
ExtentHtmlReporter htmlreporter;
@BeforeTest
public void startTest(){

htmlreporter=new ExtentHtmlReporter(new File(System.getProperty("user.dir")+"/test-output/STMExtentReport.html"));
htmlreporter.loadXMLConfig(new File(System.getProperty("user.dir")+"/extent-config.xml"));
reports=new ExtentReports();
reports.setSystemInfo("Environment", "QA");
reports.attachReporter(htmlreporter);

}
@Test
public void TC_01_TestCase(){

Assert.assertTrue(true);
testlog.log(Status.INFO,"This is Sample test one");

}

@Test
public void TC_02_TestCase(){

Assert.assertTrue(true);
testlog.log(Status.INFO,"This is Sample test one");

}
@BeforeMethod
public void register(Method method){ //reflection concepts....

String testName=method.getName();
testlog=reports.createTest(testName);
}

@AfterMethod
public void captureStatus(ITestResult result){ // runtime testcase status
if(result.getStatus()==ITestResult.SUCCESS){

testlog.log(Status.PASS, "The Test Method as : "+result.getName()+"is passed");
}
else if(result.getStatus()==ITestResult.FAILURE){
testlog.log(Status.PASS, "The Test Method as : "+result.getName()+"is Failed");
            testlog.log(Status.FAIL, "The  failure  :"+result.getThrowable());
}
else if(result.getStatus()==ITestResult.SKIP){
testlog.log(Status.PASS, "The Test Method as : "+result.getName()+"is Passed");
  }
}

@AfterTest
public void cleanUp(){
reports.flush();

}
}

Post a Comment

3 Comments

  1. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.… I love to read your Software QA services articles because your writing style is too good, its is very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    ReplyDelete