Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created June 14, 2024 12:55
Show Gist options
  • Save SarahElson/a97812e7dcf00bcca08a4ede0eced32f to your computer and use it in GitHub Desktop.
Save SarahElson/a97812e7dcf00bcca08a4ede0eced32f to your computer and use it in GitHub Desktop.
How To Generate Extent Reports In Selenium
package CloudGrid;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.aventstack.extentreports.Status;
public class AlertTests extends BaseTest
{
@Test
public void testSimpleAlertMessage()
{
String methodName = new Exception().getStackTrace()[0].getMethodName();
System.out.println("Test execution started : " + methodName);
extentTest = extentReports.createTest(methodName,"simple_alert_message");
extentTest.log(Status.INFO,"Starting test to verify simple alert message");
//click on Bootstrap alerts
extentTest.log(Status.INFO,"Clicking on Bootstrap Alerts");
driver.findElement(By.linkText("Bootstrap Alerts")).click();
//click on Normal success message
extentTest.log(Status.INFO,"Clicking on Normal Success Message");
driver.findElement(By.xpath("//*[text()='Normal Success Message']")).click();
//fetch actual message and compare it with the expected message
String expectedMessage = "×\nNormal success message. To close use the close button.";
String actualMessage = driver.findElement(By.xpath("//*[contains(@class,'alert-success-manual')]")).getText();
Assert.assertEquals(actualMessage, expectedMessage, "Expected and actual message do not match.");
extentTest.log(Status.INFO,"Verified the expected message as : " + expectedMessage);
status = "passed";
System.out.println("Test execution completed : " + methodName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment