Analyse the Result of TestNG

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

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

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

Let's learn how to generate reports in TestNG wth 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.
testng options

2. On the right to console tab you can also see "Result of Running Class" on that tab you can see details like what are passed,failed or skipped tests
testng options

3. Right Click on the project and Select Refresh option
refresh testng options

4. Now on you could see test-output folder in the Project folder
test output

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

7. TestNG test-output folder contains below items
inside out put folder testNg

8. Open the index which contains report nad what test case it is,and passed tests and failed tests ,time details.
refresh testng options

9. Open emailable report which we can email because it contains clear information about when test started and what test it is and what class it is.
refresh testng options

10. You can find 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 above program it openGoogle and openGmail methods will fail and TestNG generates emailable report for it and the report looks like below.
testng options

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

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

After looking this report first Questions asks is "when those are failed ?".
Because there is 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");"
reporting the logs

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.
reporting the logs

Handle dropdowns in selenium

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Copyright © CherCher Tech