👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.
👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.
👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.
👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.
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);
}
}
}
👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.
WebDriverManager is a library in Java that allows for easy setup and management of web drivers for different browsers such as Chrome, Firefox, and Edge. The main benefits of using WebDriverManager are:
1. Automatic driver management: WebDriverManager automatically downloads the required driver binaries and sets up the system properties, making it easier to use different web drivers without manual intervention.
2. Easy setup: Using WebDriverManager eliminates the need to download and set up the web driver executable file separately. The library handles everything for you.
3. Cross-platform support: WebDriverManager supports multiple operating systems, including Windows, Mac, and Linux.
4. Integration with testing frameworks: WebDriverManager can be easily integrated with popular testing frameworks like JUnit and TestNG, allowing for seamless web driver management during test automation.
5. Improved maintenance: By using WebDriverManager, you can avoid issues related to outdated driver versions or incompatible operating systems. It helps ensure that you have the latest version of the driver, thereby reducing the maintenance effort required to keep your test automation suite up-to-date.
👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.
📬 Contact Me | LinkedIn | GitHub
📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.