Tuesday, April 11, 2023
Saturday, April 8, 2023
How to Implement Continuous Integration in Test Automation
How CI Helps:
- This process helps to detect and fix bugs early in the development cycle, leading to faster and more efficient software delivery.
- In the context of software testing, continuous integration refers to the automated testing process that is triggered whenever new code changes are integrated into the main codebase.
- The goal of this process is to ensure that the newly added code does not break the existing functionality of the application.
- Here's an example of how continuous integration works in software testing:
- You can consider the Amazon website or any other e-commerce website.
- Suppose a software development team is working on an e-commerce application that allows users to purchase products online.
- The team uses a continuous integration tool such as Jenkins to automatically build and test the application every time a developer makes a code change and pushes it to the central code repository.
- Whenever a developer makes a code change, Jenkins automatically pulls the latest code from the repository, builds the application, and runs a suite of automated tests to check if the application is still functioning correctly.
- If any of the tests fail, the developer is notified immediately so they can fix the issue before it causes further problems.
Conclusion:
- Continuous integration ensures that any new code changes are thoroughly tested before they are integrated into the main codebase, reducing the likelihood of introducing bugs or breaking existing functionality.
- This helps to improve the quality of the software and accelerates the development process.
The Ultimate Guide to Smoke and Sanity Testing
- Smoke testing is done when we received the new build from the developer the build is stable or not, that build is testable or not.
- Smoke testing is done by the developer and tester.
- Smoke testing is done for every new build.
- It is done on the initial build.
Sanity Testing:
- Sanity testing is done at the release time of the software, it checks the main functionality of the software without going deeper.
- Sanity testing is done by the tester only.
- Sanity testing is done when the build is stable.
- It is planned when we don't have sufficient time to test the software.
Thursday, March 30, 2023
Where Can You Find Free SELENIUM REAL TIME PROJECT Resources
- ChromeOptions
- TestNG
- Maven
- Extent Report
- Data Provider Method
- Excel File Read (JXL)
- Send Reports Automatically to Email
- Failed Tests Screenshots
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
Webdriver Manager: A Comprehensive Overview of Its Benefits
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.