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");
}
}
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");
}
}
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.
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.
Handle dropdowns in selenium