Friday 19 October 2018

How to handle SSL Certificate Error using Selenium Webdriver\

Image result for ssl certificate



\

Suppose we have written test scripts and while running those script, if you encounter situation like "Untrusted Connection" then how do we handle such exception in Selenium automation.

In such cases we have to adjust our script in such way that, it will take care of SSL exception by itself.

Some desired capabilities being used to configure webdriver instance. Through this capabililties one can configure all driver instances like ChromeDriver, FireFoxDriver and Internet Explorer.

SSL Certificate Error Handling in Chrome
To handle such case in Chrome, one needs to use desired capabilities of Selenium webdriver. Below snippet will help to accept all SSL certificate in Chrome. 
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()       
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true) 
WebDriver driver = new ChromeDriver (handlSSLErr); 

SSL Certificate Error Handling in Firefox

To handle such case in Chrome, one needs to use desired capabilities of Selenium webdriver. Below snippet will help to accept all SSL certificate in Chrome. 

1) Pre-requisite is, one needs to create new firefox profile say "myProfile" 
2) Now access myProfile in the script as below and create it's object.

ProfilesIni prof = new ProfilesIni()    
FirefoxProfile ffProfile= prof.getProfile ("myProfile")
3) Now we need to configure "SetAcceptUntrustedCertificates" and "setAssumeUntrustedCertificateIssuer" properties in the FireFox  profile

ffProfile.setAcceptUntrustedCertificates(true) 
ffProfile.setAssumeUntrustedCertificateIssuer(false)
4) Now use FireFox profile in FireFox driver instance.

WebDriver driver = new FirefoxDriver (ffProfile)   
Note: "setAcceptUntrustedCertificates" and "setAssumeUntrustedCertificateIssuer" are capabilities to handle the certificate errors in web browsers.


---------------------------

No comments:

Post a Comment

Select Language