Analyze the Result of TestNG

Selenium along with TestNG, allows the user to generate reports. Generating a Report for test automation execution is an essential part of the automation.

Execution reports play a crucial role in the formation of a sophisticated automation framework.

Reports not only capture the failures, but it also captures, which is causing the failures and details about the failures.

Let's learn how to generate reports in TestNG with selenium webdriver, consider below test code.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class TestNGClass
{
	@Test
	public void openSelenium()
	{
		WebDriver driver=new FirefoxDriver();
		driver.get("https://chercher.tech/java/analyze-testng-result");
	}
}

Steps to Generate TestNG report in selenium

  1. After execution on the console, you see the details like PASSED and Failed, Skipped, and time taken to execute.
  2. console%20selenium%20webdriver

    2. On the right to console tab you can also see "Result of Running Class" on that tab you can see details like what is passed, failed or skipped tests
  3. result%20selenium%20webdriver

    3. Right Click on the project and Select Refresh option
  4. refresh%20selenium%20webdriver

    4. Now on you could see a test-output folder in the Project folder
  5. test-output%20selenium%20webdriver

    5. After execution TestNG by default create this folder and updated if the folder already exists
    6. Open the test-output folder with the system(not with eclipse)
  6. sys-test-output%20selenium%20webdriver

    7. TestNG test-output folder contains below items
  7. inside-output-folder%20selenium%20webdriver

    8. Open the index, which contains report nad what test case it is, and passed tests and failed tests, time details.
  8. testng%20report%20selenium%20webdriver

    9. Open emailable report, which we can email because it contains clear information about when the test started and what test it is and what class it is.
  9. email%20report%20selenium%20webdriver

    10. You can find a few more files but which are not much important

Generate Detailed Reports in TestNG

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class TestNGClass
{
	WebDriver driver=new FirefoxDriver();
	@Test
	public void openSeleniumMentor()
	{
		driver.get("https://chercher.tech");
	}

	@Test
	public void openGoogle()
	{
		//fails
		driver.get("www.google.com");
	}
	@Test
	public void openGmail()
	{
		//fails
		driver.get("gmail.com");
	}

}

  1. Lets us consider the above program it openGoogle and openGmail methods will fail, and TestNG generates an emailable report for it, and the report looks like below.
  2. email%20report%20no%20details%20selenium%20webdriver

    2. Is it possible to send the above report to the client as it is ?
    No

    Because the client is a person who pays you and also always screws you with questions.

    After looking at this report, the first Question asks is, "when those are failed ?".
    Because there are no details about when it is failed in the report.
    This is not feasible

Learn OOPS in Selenium and Java

Let's see how to add details to the report

  1. Got to the program and add a code "Reporter.log("google opened");"
  2. report%20program%20selenium%20webdriver

    2. Enter the code where ever you want details or logs.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Reporter;
import org.testng.annotations.Test;

public class TestNGClass
{
	WebDriver driver=new FirefoxDriver();
	@Test
	public void openSelenium()
	{
		Reporter.log("opening chercher.tech");
		driver.get("https://chercher.tech");
		Reporter.log("chercher.tech opened");
	}

	@Test
	public void openGoogle()
	{
		Reporter.log("opening google.com");
		driver.get("https://www.google.com");
		Reporter.log("google opened");
	}
	@Test
	public void openGmail()
	{
		Reporter.log("opening gamil");
		driver.get("https://gmail.com");
		Reporter.log("gmail opened'");
	}

}


3. Now open the "emailable-report," it contains all the logs now.

testng%20log%20selenium%20webdriver

Handle dropdowns in selenium

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions