TestNG Report Generation in selenium | Part-2
Step to Run the Method
- Create new class in a regular package and write the given below code
package asc;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;
import common.BaseTest;
public class Report extends BaseTest{
@Test
public void reporterTest1() {
System.out.println("This is test 1");
driver.get("https://google.com/");
Assert.assertTrue(false);
}
@Test
public void reporterTest2() {
Reporter.log("This is test 2");
System.out.println("This is test 2");
}
@Test
public void reporterTest3() {
Reporter.log("This is test 3");
System.out.println("This is test 3");
}
@Test
public void reporterTest4() {
System.out.println("This is test 4");
}
@Test
public void reporterTest5() {
System.out.println("This is test 5");
}
}
- Make change in Listener class which is there in a common package as per given below
package common;
import java.io.IOException;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.Reporter;
import screensclick.ScreenShotTest;
//import asc.ScreenShotTest;
public class Listeners extends ScreenShotTest implements ITestListener{
public void onTestStart(ITestResult result) {
Reporter.log("Mehtod Name is -"+ result.getName());
System.setProperty("org.uncommons.reportng.title", "Akhil Chukkalwar");
System.out.println("Test case is Starting");
}
public void onTestSuccess(ITestResult result) {
Reporter.log("Status of execution -"+result.getStatus());
}
public void onTestFailure(ITestResult result) {
System.out.println("Test Failed - Screenshot Captured");
try {
getScreenshot();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.setProperty("org.uncommons.reportng.escape-output", "false");
Reporter.log("< a href=\"C:\\eclipse-workspace\\Selenium-workspace\\screenshot\">Test Resua>");
}
public void onTestSkipped(ITestResult result) {
}
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}
public void onStart(ITestContext context) {
}
public void onFinish(ITestContext context) {
}
}
- And then Create on Test Suite or XML file and make change as given below
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
< suite name="Listeners test">
< listeners>
< listener class-name="common.Listeners" />
< listener class-name="org.uncommons.reportng.HTMLReporter" />
< /listeners>
< test name="Report Testing">
< classes>
< class name="asc.Report"/>
< /classes>
< /test>
< /suite>
- And Then Add the dependency in the pox.xml file which is given below
< !-- https://mvnrepository.com/artifact/com.github.sdrss/reportng -->
< dependency>
< groupId>com.github.sdrss< /groupId>
< artifactId>reportng< /artifactId>
< version>2.7.0< /version>
< scope>test< /scope>
< /dependency>
- And then Run the Code
- Check the Report in test-output same as before
- due to dependency in test-output Create one folder html click on that and open the folder
- open the index.html file and check the report