Latest post from this blog

How to Manage Test Execution Across Different Browsers and Environments (QA, UAT, Staging)

In real-time automation projects, test execution is never limited to a single browser or a single environment . Applications must be validated across multiple browsers (Chrome, Firefox, Edge) and multiple environments such as QA, UAT, and Staging before going live. A well-designed Selenium + Java + Cucumber automation framework should allow testers to switch browsers and environments easily without changing test scripts . This blog explains how to manage test execution efficiently across different browsers and environments using best practices followed in real projects. Why Multi-Browser and Multi-Environment Testing Is Important Different users use different browsers QA, UAT, and Staging environments have different configurations Bugs may appear only in specific environments or browsers Same test cases must be validated everywhere before production release Common Challenges Testers Face Hardcoded browser names and URLs Maintaining separate test scripts for each environment Browse...

Handling HTTPS Websites and SSL Certificate Errors in Selenium

Why SSL Certificate Errors Occur 
SSL certificates ensure secure communication between the server and browser. If there's an issue, like an untrusted or expired certificate, the browser shows a warning. In automation, these warnings can interrupt tests, causing them to fail unless managed properly.In this post, we'll explain how to handle SSL certificate errors in Selenium for Chrome, Firefox, and Edge to ensure your tests run smoothly.

setAcceptInsecureCerts(true) option allows the browser to ignore SSL certificate errors, enabling Selenium tests to run smoothly on sites with untrusted or invalid certificates.

Handling SSL Certificate Errors in Chrome
You can configure Chrome to accept insecure certificates by passing the option in ChromeOptions.

ChromeOptions.setAcceptInsecureCerts(true) allows Chrome to skip SSL warnings and continue testing on sites with untrusted certificates.its similar to the Firefox and Edge Browser also.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class HandleSSLCertificateChrome {

public static void main(String[] args) {
// Set up ChromeDriver path
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

// Set Chrome options to ignore certificate errors
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true); // This will ignore the SSL certificate errors

// Initialize WebDriver
WebDriver driver = new ChromeDriver(options);

// Navigate to HTTPS site
driver.get("https://Enter Your URL.com/");

System.out.println("Page Title: " + driver.getTitle());

// Close the browser
driver.quit();
}
}

Handling SSL Certificate Errors in Firefox
With Firefox, you can achieve the same by configuring FirefoxOptions
FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(options);
//Initialize WebDriver
WebDriver driver = new FirefoxDriver(options);
// Navigate to HTTPS site
driver.get("https://Enter Your URL.com")

Handling SSL Certificate Errors in Edge
Edge also has options similar to Chrome to bypass SSL certificate errors

// Set Edge options to ignore certificate errors
EdgeOptions options = new EdgeOptions();
options.setAcceptInsecureCerts(true);
// Initialize WebDriver
WebDriver driver = new EdgeDriver(options);
// Navigate to HTTPS site
driver.get("https://"Enter Your URL.com");
Conclusion 
Handling SSL certificate errors on HTTPS websites can be tricky but is essential for smooth Selenium automation. By using setAcceptInsecureCerts(true) in Chrome, Firefox, and Edge, you can skip these warnings and maintain test flow.

Comments

Popular posts from this blog

How to Manage Test Execution Across Different Browsers and Environments (QA, UAT, Staging)

Purpose of the StepData Class in Selenium + Java Cucumber Automation Framework

Ensuring Thread Safety in Parallel Test Execution with Selenium, Cucumber, and Java