Showing posts with label TestNG. Show all posts
Showing posts with label TestNG. Show all posts

Thursday, March 30, 2023

Where Can You Find Free SELENIUM REAL TIME PROJECT Resources

 This project includes the following frameworks and libraries:
  1.  ChromeOptions
  2.  TestNG
  3.  Maven
  4.  Extent Report
  5.  Data Provider Method
  6.  Excel File Read (JXL)
  7.  Send Reports Automatically to Email
  8.  Failed Tests Screenshots
Selenium Code:

package Practice;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.lang.reflect.Method;

import java.text.SimpleDateFormat;

import java.time.Duration;

import java.util.Date;

import java.util.Properties;

import java.util.concurrent.TimeUnit;

import javax.activation.DataHandler;

import javax.activation.DataSource;

import javax.activation.FileDataSource;

import javax.mail.BodyPart;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;

import org.testng.ITestResult;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.AfterSuite;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;

import jxl.Sheet;

import jxl.Workbook;

import jxl.read.biff.BiffException;

public class Selenium_Test {

public WebDriver driver;

public ExtentReports extent;

public ExtentTest extentTest;

@SuppressWarnings("deprecation")

@BeforeMethod

public void setup(Method method) {

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.addArguments("--remote-allow-origins=*");

this.driver = new ChromeDriver(chromeOptions);

driver.manage().window().maximize();

driver.manage().deleteAllCookies();

driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));

driver.get("https://suriyaparithy.blogspot.com/");

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

extentTest = extent.startTest(method.getName(), "This is a test for " + method.getName());

}

@BeforeTest(alwaysRun = true)

public void setExtent() {

extent = new ExtentReports("./test-output/Reports/Report.html", true);

extent.addSystemInfo("User Name", "Suriya");

extent.addSystemInfo("Environment", "Automation Testing");

extent.addSystemInfo("Application", "Blog");

extent.addSystemInfo("Test Scenario", "Functionality Testing");

}

public String getScreenshot(WebDriver driver, String screenshotName) throws IOException {

String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());

TakesScreenshot ts = (TakesScreenshot) driver;

File source = ts.getScreenshotAs(OutputType.FILE);

String destination = System.getProperty("user.dir") + "/FailedTestsScreenshots/" 

+ screenshotName + dateName + ".png";

File finalDestination = new File(destination);

FileUtils.copyFile(source, finalDestination);

return destination;

}

// DATA PROVIDER METHOD in JXL

String[][] data = null;

@DataProvider(name = "loginData")

public String[][] loginDataProvider() throws BiffException, IOException {

data = getExcelData();

return data;

}

public String[][] getExcelData() throws BiffException, IOException {

FileInputStream excel = new FileInputStream("D:\\SUR\\src\\test\\resources\\login.xls");

Workbook workbook = Workbook.getWorkbook(excel);

Sheet sheet = workbook.getSheet(0);

int rowCount = sheet.getRows();

int columnCount = sheet.getColumns();

String testData[][] = new String[rowCount - 1][columnCount];

for (int i = 1; i < rowCount; i++) {

for (int j = 0; j < columnCount; j++) {

testData[i - 1][j] = sheet.getCell(j, i).getContents();

}

}

return testData;

}

@Test(enabled = true, priority = 1)

public void testExcelData() {

System.out.println("suriya");

}

@AfterMethod(alwaysRun = true)

public void Down(ITestResult result) throws IOException {

if (result.getStatus() == ITestResult.FAILURE) {

extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS " + result.getName());

extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS " + result.getThrowable());

String screenshotPath = getScreenshot(driver, result.getName());

extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath));

} else if (result.getStatus() == ITestResult.SKIP) {

extentTest.log(LogStatus.SKIP, "Test Case SKIPPED IS " + result.getName());

} else if (result.getStatus() == ITestResult.SUCCESS) {

extentTest.log(LogStatus.PASS, "Test Case PASSED IS " + result.getName());

}

extent.endTest(extentTest);

// driver.quit();

}

@AfterTest(alwaysRun = true)

public void endReport() {

extent.flush();

// extent.close();

}

@AfterSuite

public void sendEmailReport() {

Properties props = new Properties();

props.put("mail.smtp.host", "smtp.gmail.com");

props.put("mail.smtp.socketFactory.port", "465");

props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.port", "465");

Session session = Session.getDefaultInstance(props,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("yourgmail@gmail.com", "your app password");

}

});

try {

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress("your@gmail.com"));

message.setRecipients(Message.RecipientType.TO,

InternetAddress.parse("email1@gmail.com, email2@gmail.com"));

message.setSubject("Automation Testing Report");

BodyPart messageBodyPart1 = new MimeBodyPart();

messageBodyPart1.setText("This is testng report");

String[] filenames = { "D:\\SURIYA\\test-output\\emailable-report.html",

"D:\\SURIYA\\test-output\\index.html" };

Multipart multipart = new MimeMultipart();

for (String filename : filenames) {

MimeBodyPart messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(filename);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName(filename);

multipart.addBodyPart(messageBodyPart);

}

message.setContent(multipart);

Transport.send(message);

System.out.println("=====Email Sent=====");

} catch (MessagingException e) {

throw new RuntimeException(e);

}

}

}

Wednesday, March 29, 2023

How To Use CROSS BROWSER TESTING IN SELENIUM WEBDRIVER

 package Practice;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxOptions;

import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class WebDriver {

@Test

public void testChrome() {

ChromeOptions chromeOptions = new ChromeOptions();

WebDriverManager.chromedriver().setup();

ChromeDriver driver = new ChromeDriver(chromeOptions);

driver.get("https://suriyaparithy.blogspot.com/");

driver.quit();

}

@Test

public void testFirefox() {

FirefoxOptions firefoxOptions = new FirefoxOptions();

WebDriverManager.firefoxdriver().setup();

FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

driver.get("https://suriyaparithy.blogspot.com/");

driver.quit();

}

}


testng.xml file:

<suite name="My Test Suite" parallel="tests">

<test name="Chrome Test">

<classes>

<class name="Practice.WebDriver">

<methods>

<include name="testChrome" />

</methods>

</class>

</classes>

</test>

<test name="Firefox Test">

<classes>

<class name="Practice.WebDriver">

<methods>

<include name="testFirefox" />

</methods>

</class>

</classes>

</test>

</suite>

Tuesday, March 28, 2023

Quick & Easy Method to Send TestNG Reports via Email in Selenium WebDriver

package Practice;

import java.util.Properties;

import javax.activation.DataHandler;

import javax.activation.DataSource;

import javax.activation.FileDataSource;

import javax.mail.BodyPart;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

public class SendMailSSLWithAttachment {

public static void main(String[] args) {

// Create object of Property file

Properties props = new Properties();

// this will set host of server- you can change based on your requirement

props.put("mail.smtp.host", "smtp.gmail.com");

// set the port of socket factory

props.put("mail.smtp.socketFactory.port", "465");

// set socket factory

props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

// set the authentication to true

props.put("mail.smtp.auth", "true");

// set the port of SMTP server

props.put("mail.smtp.port", "465");

// This will handle the complete authentication

Session session = Session.getDefaultInstance(props,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("youremail@gmail.com", "email-app-password");

}

});

try {

// Create object of MimeMessage class

Message message = new MimeMessage(session);

// Set the from address

message.setFrom(new InternetAddress("from@gmail.com"));

// Set the recipient address

message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("s@gmail.com"));

// Add the subject link

message.setSubject("Automation Testing Report");

// Create object to add multimedia type content

BodyPart messageBodyPart1 = new MimeBodyPart();

// Set the body of email

messageBodyPart1.setText("This is testng report");

// Create another object to add another content

MimeBodyPart messageBodyPart2 = new MimeBodyPart();

// Mention the file which you want to send

String filename = "D:\\SURIYA\\test-output\\emailable-report.html";

// Create data source and pass the filename

DataSource source = new FileDataSource(filename);

// set the handler

messageBodyPart2.setDataHandler(new DataHandler(source));

// set the file

messageBodyPart2.setFileName(filename);

// Create object of MimeMultipart class

Multipart multipart = new MimeMultipart();

// add body part 1

multipart.addBodyPart(messageBodyPart2);

// add body part 2

multipart.addBodyPart(messageBodyPart1);

// set the content

message.setContent(multipart);

// finally send the email

Transport.send(message);

System.out.println("=====Email Sent=====");

} catch (MessagingException e) {

throw new RuntimeException(e);

}

}

}

NOTE:

  1. Download this repository
  • https://mvnrepository.com/artifact/javax.mail/javax.mail-api/1.6.2
  • https://mvnrepository.com/artifact/com.sun.mail/javax.mail/1.6.2
  • https://mvnrepository.com/artifact/javax.activation/activation/1.1.1

Monday, March 20, 2023

Dropdown Handling with Selenium WebDriver: Tips and Techniques

 import java.time.Duration;

import java.util.ArrayList;

import java.util.List;

import java.util.stream.Collectors;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class Example {

WebDriver driver;

@BeforeTest

public void setUp() {

WebDriverManager.chromedriver().setup();

driver = new ChromeDriver();

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

driver.manage().window().maximize();

driver.get("https://www.amazon.com/");

}

@Test

public void dropdownTest() {

WebElement dropdown = driver.findElement(By.id("searchDropdownBox"));

Select select = new Select(dropdown);

// Print the first selected option and assert if it equals “All Departments”.

String firstSelectedOption = select.getFirstSelectedOption().getText();

System.out.println("firstSelectedOption = " + firstSelectedOption);

if (firstSelectedOption.equals("All Departments")) {

System.out.println("PASS");

} else {

System.out.println("FAIL");

}

// Print all of the drop down options-getOptions(); method returns the List<WebElement>. 

Using a loop, print all options.

List<WebElement> allOptions = select.getOptions();

for (WebElement eachOption : allOptions) {

System.out.println(eachOption.getText());

}

// Print the total number of options in the dropdown

int totalNumOfOptions = select.getOptions().size();

System.out.println("numOfOptions = " + totalNumOfOptions);

// if ‘Appliances’ is a drop-down option. Print true if “Appliances” is

// an option. Print false otherwise.

List<String> listOfOptions = new ArrayList<>();

for (WebElement eachOption : allOptions) {

listOfOptions.add(eachOption.getText());

}

System.out.println("listOfOptions = " + listOfOptions);

if (listOfOptions.contains("Appliances")) {

System.out.println("TRUE");

} else {

System.out.println("FALSE");

}

// Assert if the dropdown is in Alphabetical Order

List<String> sortedList = listOfOptions.stream().sorted().collect(Collectors.toList());

System.out.println("sortedList = " + sortedList);

}

@AfterTest

public void tearDown() {

driver.quit();

}

}

Tuesday, August 2, 2022

Selenium using Data Provider Method

 package coaching;


import java.time.Duration;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;


public class DataProviderTest {

WebDriver driver;

@DataProvider(name = "Authentication")

 public static Object[][] credentials() {

           // The number of times data is repeated, test will be executed the same no. of times

          // Here it will execute two times

           return new Object[][] { { "suriya", "Test@123" }, { "parithy", "Test@123" }};

     }

@Test(dataProvider = "Authentication")


  public void test(String username, String password) {

System.setProperty("webdriver.chrome.driver", "F:\\Suriya\\chromedriver.exe");

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().deleteAllCookies();

driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));

driver.get("URL");

WebElement username1 = driver.findElement(By.id("userName"));

username1.sendKeys(username);

                       WebElement password1 = driver.findElement(By.id("pwd"));

password1.sendKeys(password);

                      WebElement login = driver.findElement(By.cssSelector(".btn:nth-child(3)"));

login.click();

   }

}


Saturday, July 30, 2022

Selenium Tests using Data Provider and TestNG

 package coaching;


import java.io.File;

import java.io.FileInputStream;

import java.io.FileReader;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.time.Duration;

import java.util.Date;

import java.util.Properties;


import org.apache.commons.io.FileUtils;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.ITestResult;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;


import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;


public class Login_Page {

public WebDriver driver;

public ExtentReports extent;

public ExtentTest extentTest; //helps to generate the logs in test report.

@BeforeTest

public void setExtent(){

// initialize the HtmlReporter

extent = new ExtentReports("./src/test/resources/Reports/LoginPageReport.html", true); // true - new data insert into report,false-append the old data

//To add system or environment info by using the addSystemInfo method.

extent.addSystemInfo("User Name", "Suriya");

extent.addSystemInfo("Environment", "Automation Testing");

extent.addSystemInfo("Application","Learning Online Course "); 

extent.addSystemInfo("Test Scenario","Login Functionality");


}

@AfterTest

public void endReport(){


extent.flush(); // Flush method is used to erase any previous data on the report and create a new report.

//extent.close(); 

}

public static String getScreenshot(WebDriver driver, String screenshotName) throws IOException{

String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());

TakesScreenshot ts = (TakesScreenshot) driver;

File source = ts.getScreenshotAs(OutputType.FILE);

// after execution, you could see a folder "FailedTestsScreenshots"

// under src folder

String destination = System.getProperty("user.dir") + "/FailedTestsScreenshots/" + screenshotName + dateName

+ ".png";

File finalDestination = new File(destination);

FileUtils.copyFile(source, finalDestination);

return destination;

}

@BeforeMethod

public void setup() throws InterruptedException, IOException {


System.setProperty("webdriver.chrome.driver", "F:\\Suriya\\chromedriver.exe");

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().deleteAllCookies();

driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));

driver.get("URL");

}

@Test (dataProvider = "getData") 

public void login(String Username, String Password) {

extentTest = extent.startTest("Enter username and password");

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));

WebElement username = driver.findElement(By.id("userName"));

username.sendKeys(Username);

WebElement password = driver.findElement(By.id("pwd"));

password.sendKeys(Password);

WebElement login = driver.findElement(By.cssSelector(".btn:nth-child(3)"));

login.click();

}

@DataProvider(name = "getData") 

// Declare a method whose return type is an array of object. 

    public Object[ ][ ] dataProviderMethod() 

    {

// Create an object of an array object and declare parameters 3 and 2. 

// 3 represents the number of times your test has to be repeated. 

// 2 represents the number of parameters in test data. Here, we are providing two parameters. 

     Object[ ][ ] data = new Object[3][2]; 


// 1st row. 

      data[0][0] = "John"; 

      data[0][1] = "23RYRTE7E5"; 


// 2nd row. 

     data[1][0] = "Sanjana"; 

     data[1][1] = "40EEUE5"; 


// 3rd row. 

     data[2][0] = "Deep"; 

     data[2][1] = "01E575E"; 

      return data; 

   } 

@AfterMethod

public void Down(ITestResult result) throws IOException{


if(result.getStatus()==ITestResult.FAILURE){

extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS "+result.getName()); //to add name in extent report

extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS "+result.getThrowable()); //to add error/exception in extent report


String screenshotPath = getScreenshot(driver, result.getName());

extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath)); //to add screenshot in extent report

//extentTest.log(LogStatus.FAIL, extentTest.addScreencast(screenshotPath)); //to add screencast/video in extent report

}

else if(result.getStatus()==ITestResult.SKIP){

extentTest.log(LogStatus.SKIP, "Test Case SKIPPED IS " + result.getName());

}

else if(result.getStatus()==ITestResult.SUCCESS){

extentTest.log(LogStatus.PASS, "Test Case PASSED IS " + result.getName());


}



extent.endTest(extentTest); //ending test and ends the current test and prepare to create html report

driver.quit();

}

}



Wednesday, May 18, 2022

Selenium Java - Shadow DOM, TestNG, Properties File, Extent Reports, Screenshot

 package selenium;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java. text.SimpleDateFormat;

import java.util.Date;

import java.util.Properties;

import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.ITestResult;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;

import io.github.sukgu.Shadow;



public class Job_Failure_Login_Page_NG {

public WebDriver driver;

public ExtentReports extent;

public ExtentTest extentTest; 



@BeforeTest

public void setExtent(){

  extent = new ExtentReports(System.getProperty("user.dir")+"/test output/result/LoginPageReport.html", true); 

//To add system or environment info by using the add system info method.

extent.addSystemInfo("User Name", "Suriya");

extent.addSystemInfo("Environment", "Automation Testing");

extent.addSystemInfo("Application","Job"); 

extent.addSystemInfo("Test Scenario","Login Functionality");


}


@AfterTest

public void endReport(){

extent.flush(); 

      //extent.close(); 

}



public static String getScreenshot(WebDriver driver, String screenshotName) throws IOException{

String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());

TakesScreenshot ts = (TakesScreenshot) driver;

File source = ts.getScreenshotAs(OutputType.FILE);

// after execution, you could see a folder "FailedTestsScreenshots"

// under src folder

String destination = System.getProperty("user.dir") + "/FailedTestsScreenshots/" + screenshotName + dateName  + ".png";

File finalDestination = new File(destination);

FileUtils.copyFile(source, finalDestination);

return destination;

}


@BeforeMethod

public void setup() throws InterruptedException, IOException {

System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");

driver = new ChromeDriver(); 

driver.manage().window().maximize();

driver.manage().deleteAllCookies();

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

driver.get("URL");

Thread.sleep(3000);



}

  @Test(enabled=true,priority=0)

  public void user_and_password_correct() throws InterruptedException, IOException {

  extentTest = extent.startTest("Enter correct username and password");

  Shadow shadow = new Shadow(driver);

  WebElement element = shadow.findElement("amplify-form-section");

  //File Read

  FileReader reader=new FileReader("datafile.properties");

  Properties p=new Properties();  

  p.load(reader);

  

  extentTest.log(LogStatus.INFO, "Enter valid Username");

  element.findElement(By.id("username")).sendKeys(p.getProperty("username"));

  extentTest.log(LogStatus.INFO, "Enter valid Password");

  element.findElement(By.id("password")).sendKeys(p.getProperty("password"));

 

  extentTest.log(LogStatus.INFO, "Click on the SIGN IN button "); 

  WebElement signin = element.findElement(By.cssSelector("[class=button][type=submit]"));

  signin.submit();

  extentTest.log(LogStatus.INFO, "Home Page Open");

  Thread.sleep(3000);

  driver.findElement(By.linkText("LogOut")).click();

  Thread.sleep(5000);

   

 }


  
  @AfterMethod

public void Down(ITestResult result) throws IOException{


      if(result.getStatus()==ITestResult.FAILURE){

       extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS "+result.getName()); //to add name in extent report

extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS "+result.getThrowable()); //to add error/exception in extent report

            String screenshotPath = getScreenshot(driver, result.getName());

extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath)); //to add screenshot in extent report

//extentTest.log(LogStatus.FAIL, extentTest.addScreencast(screenshotPath)); 
    //to add screencast/video in extent report

}

else if(result.getStatus()==ITestResult.SKIP){

extentTest.log(LogStatus.SKIP, "Test Case SKIPPED IS " + result.getName());

}

else if(result.getStatus()==ITestResult.SUCCESS){

extentTest.log(LogStatus.PASS, "Test Case PASSED IS " + result.getName());


}

extent.endTest(extentTest); //ending test and ends the current test and prepare to create html report

driver.quit();

}

}