Using personal SSL certificates with Webdriver (Selenium 2.0)

I am testing a website that requires personalized SSL certificates to perform certain actions, such as logging in.

I have a Webdriver test (Selenium 2.0) that I installed 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 allow access to the home page. Then the test then clicks the login button, enters the correct credentials and clicks the "Submit" button. At this point, the browser enters the download state, and I assume that the SSL certificate is missing on my side and therefore cannot connect to the login service.

I searched for different proxy solutions and found this:

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

So I added it to 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 the x directory, 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); } 

Thanks Beccy

+6
source share
3 answers

Webdriver does not have a built-in mechanism for adding a personal certificate.

If you are using firefox, the only way I found for this is to create a firefox profile and add a certificate to it. Then you can reuse the profile when doing OR tests, and this is my preferred option, take the cert8.db and key3.db files and add them to the profile that the webdriver creates at runtime.

I'm not sure how to do this in java, but in ruby ​​I override the layout_on_disk method of FirefoxProfile to add additional files that I need. Java has the same class so you can do the same.

+5
source

There is no need to rewrite the layout_on_disk () method as suggested.
You can simply upload the folder containing the cert8.db and key3.db files as a profile.

Selenium will fill out a profile for you.

Then you can add the settings necessary for the firefox profile.
The resulting code is as follows:

  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.

+1
source

Webdriver can do this, although Derek is right and it is not built-in.

All you have to do is create a custom Trust Manager that trusts all certificates and then also overrides the "host verifier" to resolve the unrealistic domain name.

Here are some examples I found here on Google:

 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 that you would use with Apache HC components to override SSL settings without using WebDriver. I used this method a lot with direct HTTP messages using the Apache HT components, and it “appears” that from the link above, this concept should also work with WebDriver.

0
source

Source: https://habr.com/ru/post/885394/


All Articles