SSL certificate error handling

What is SSL Certificate?
SSL (Secure Sockets Layer) is a standard technology to establish encrypted connection between the server and the client which is a browser.

SSL-secured websites begin with https:// and you can see a lock icon or green address bar if the connection is securely established.

SSL certificate error handling in selenium

What is untrusted certificate?
This is the error presented by web browsers when you access a site that has a security certificate installed (for SSL/TLS data encryption) that cannot be verified by the browser.

SSL certificate error handling in selenium
Types of SSL Certificate Error:
  1. Firefox: This connection is untrusted.
  2. Google Chrome: This site security is not trusted.
  3. Internet Explorer : This security certificate presented by this website was not trusted by a trusted certificate authority (CA).
Please see the following steps that we can add in the Selenium Script to handle the above situation of "Untrusted Connection.".

SSL Certificate Error Handling in Firefox:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class Demo {
 public static void main(String[] args) {
  System.setProperty("webdriver.gecko.driver", "./ProjectSelenium/driver/geckodriver.exe");

  // Creating a custom profile in Firefox to accept untrusted SSL cert
  FirefoxProfile profile = new FirefoxProfile();

  profile.setAcceptUntrustedCertificates(true);
  profile.setAssumeUntrustedCertificateIssuer(false);

  WebDriver driver = new FirefoxDriver(profile);
  driver.get("https://cacert.org/");
 }
}

SSL Certificate Error Handling in Chrome:
1
2
3
4
DesiredCapabilities DC = DesiredCapabilities.chrome();
DC.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.chrome.driver","chromedriver.exe");
WebDriver driver = new ChromeDriver(DC);

SSL Certificate Error Handling in Internet explorer :
1
2
3
4
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.ie.driver","IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(capabilities);


<-- Previous || Next -->

No comments:

Post a Comment