As we know SSL is mainly used to keep sensitive information encrypted when sending across the Internet, which is important because, the information that we send on the internet is passed by connecting with multiple systems to the destination server. You can know more info on this here .Different SSL certificate Errors
This is how the error looks like :
Let us now see the example :
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class SSLExample_Chrome {
private WebDriver driver;
@BeforeClass
public void setUp() {
DesiredCapabilities capability = DesiredCapabilities.chrome();
// To Accept SSL certificate
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
// setting system property for Chrome browser
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
// create Google Chrome instance and maximize it
driver = new ChromeDriver(capability);
driver.manage().window().maximize();
}
@Test
public void openApplication() {
System.out.println("Navigating application");
driver.get("https://cacert.org/");
WebElement headingEle = driver.findElement(By.cssSelector(".story h3"));
// Validate heading after accepting untrusted connection
String expectedHeading = "Are you new to CAcert?";
Assert.assertEquals(headingEle.getText(), expectedHeading);
}
@AfterClass
public void tearDown() {
if (driver != null)
driver.quit();
}
}
Unlike handling SSL certificates in firefox and chrome browser are different when it comes to IE. In IE browser, we may have to handle it using javascript like like below :
System.setProperty("webdriver.ie.driver", "D:/IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("https://cacert.org/");
driver.get("javascript:document.getElementById('overridelink').click();");
Comments
Post a Comment