SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Handle SSL Certificate Error In Google Chrome When Run Test In Selenium

You already know how to execute selenium webdriver test In Google chrome browser as we learnt It In THIS POST. You are also well aware about how to handle SSL Certificate Error In Mozilla Firefox browser by creating custom profile as described In THIS POST and In IE browser using driver.navigate() method as described In THIS POST. Now supposing you wants to run your test In google chrome browser and need to handle SSL Certificate Error. Any Idea How to do It?

Handling SSL certificate error In google chrome browser on selenium WebDriver test execution Is so simple and easy. Here we can use desired capabilities to get and accept SSL certificate on run-time using bellow given syntax.

//Set chrome browser's capabilities to to accept SSL certificate on runtime.
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

Now If you will launch Google Chrome browser using newly set capability and open URL where SSL certificate error display then It will accept SSL certificate automatically and launch site URL without any error.

Practical example to show how to handle SSL certificate error Is as bellow. Execute bellow given example In eclipse (If you have any URL where SSL certificate error appear) and observe result.

package Testing_Pack;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SSLErrorInChrome {

 public static void main(String[] args) {

  //Set chrome browser's capabilities to to accept SSL certificate on runtime.
  DesiredCapabilities capability = DesiredCapabilities.chrome();
  capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
  System.setProperty("webdriver.chrome.driver", "D:\\chromedriver_win32\\chromedriver.exe");

  WebDriver driver = new ChromeDriver(capability);
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  
  //Enter the URL of site where you facing SSL error.
  driver.get("Enter site URL");
 }
}

It will handle certificate related error and run your test smoothly. I have used above method In many of my sites and works fine for me.

1 comment: