10

I am testing a website which requires personal SSL certificates in order to do certain things, such as sign-in.

I have a Webdriver (Selenium 2.0) test that I have set up with a proxy:

    Proxy localhostProxy = new Proxy();
    localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
    localhostProxy.setHttpProxy("www-proxyname:port");
    
    FirefoxProfile profile = new FirefoxProfile();
    profile.setProxyPreferences(localhostProxy);
    driver = new FirefoxDriver(profile);

And this will access the homepage fine. The test then clicks the sign in button, enters in the correct credentials and clicks on submit. At this point the browser then goes into a loading state, and I'm assuming it's because the SSL certificate is missing from my side and therefore cannot connect to the sign in service.

I searched for different proxy solutions, and found this:

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

So I added it into my code, but it doesn't seem to do what I want. I think I'm looking for a way to tell WebDriver that my ssl certificate is in x directory, please use it when accessing this site. Does anyone know how to do this?

My Test code is:

@Test
public void userSignsInAndVerifiesDrawerViews(){
            driver.get("www.url.com");
            waitFor(5000);
    driver.findElement(By.xpath("//a[contains(text(), 'Sign in')]")).click();
    waitFor(3000);
    String username = "seleniumtest";
    String password = "seleniumtest1";
    driver.findElement(By.id("username")).sendKeys(username);
    driver.findElement(By.id("password")).sendKeys(password);
    driver.findElement(By.xpath("//signin")).click();
    waitFor(30000);
    String signInLinkText = driver.findElement(By.xpath("//xpath")).getText();
    assertEquals(signInLinkText, username);
}
1
  • Strangely, when I was running the test, I stopped it part way through and accessed the Firefox -> Preferences -> Advanced -> Encyption and selected the option to view certificates...the browser crashed on me.
    – Beccy
    Apr 11, 2011 at 15:04

3 Answers 3

9

Webdriver has no built in mechanism for adding a personal cert.

If you are using firefox the only way that I have found to do this is to create a firefox profile and add the certificate to it. You can then either reuse the profile when you run your tests OR, and this is my prefered option, take the cert8.db and key3.db files and add them to the profile that webdriver creates at runtime.

I am not sure how yo do this in java, but in ruby I override the layout_on_disk method of FirefoxProfile to add the extra files I required. Java has the same class so you should be able to do this same thing.

1
  • 1
    Link updated. I've not used this code for a while so I can't vouch for its continued relevance to the question - I can only assume it hasn't changed too much. Jan 23, 2013 at 13:54
3

No need to overwrite the method layout_on_disk() as suggested.
You can simply load as profile a folder containing the files cert8.db and key3.db.

Selenium will complete the profile for you.

Then you can add the preferences you need to the firefox profile.
The resulting code looks like this:

    FirefoxProfile firefoxProfile = new FirefoxProfile(
            new File("/folder/location"));
    FirefoxOptions options = new FirefoxOptions();

    options.setProfile(firefoxProfile);

    WebDriver driver = new RemoteWebDriver(
            new URL("http://localhost:4444/wd/hub"),
            options.toCapabilities());

Tested with selenium 3.5.3.

0

Webdriver can do this, although Derek is right and it isn't built in.

All you need to do is make a custom Trust Manager that trusts all certs and then also override the "hostname verifier" to allow a non-real domain name.

There is somewhat of an example I found on Google here:

http://grepcode.com/file/repo1.maven.org/maven2/org.seleniumhq.selenium.server/selenium-server-coreless/1.0.3/org/openqa/selenium/server/TrustEverythingSSLTrustManager.java

This is the same method you would use with Apache HC components to override SSL settings without using WebDriver. I've used this method a lot with direct HTTP posts using Apache HT components and it "appears" that from the link above , this concept should also work with WebDriver.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.