Using Personal SSL certificates with Webdriver (Selenium 2.0)(将个人 SSL 证书与 Webdriver (Selenium 2.0) 一起使用)
问题描述
我正在测试一个需要个人 SSL 证书才能执行某些操作(例如登录)的网站.
I am testing a website which requires personal SSL certificates in order to do certain things, such as sign-in.
我有一个使用代理设置的 Webdriver (Selenium 2.0) 测试:
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);
这样就可以正常访问主页了.测试然后单击登录按钮,输入正确的凭据并单击提交.此时浏览器进入加载状态,我假设这是因为我这边缺少 SSL 证书,因此无法连接到登录服务.
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);
所以我将它添加到我的代码中,但它似乎没有达到我想要的效果.我想我正在寻找一种方法来告诉 WebDriver 我的 ssl 证书在 x 目录中,请在访问此站点时使用它.有谁知道怎么做?
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?
我的测试代码是:
@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);
}
推荐答案
Webdriver 没有添加个人证书的内置机制.
Webdriver has no built in mechanism for adding a personal cert.
如果您使用的是 firefox,我发现这样做的唯一方法是创建一个 firefox 配置文件并将证书添加到其中.然后,您可以在运行测试时重用配置文件,或者,这是我的首选选项,获取 cert8.db 和 key3.db 文件并将它们添加到 webdriver 在运行时创建的配置文件中.
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.
我不知道你是如何在 java 中做到这一点的,但是在 ruby 中我覆盖了 FirefoxProfile 的 layout_on_disk 方法来添加我需要的额外文件.Java 有 same class 所以你应该可以做同样的事情.
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.
这篇关于将个人 SSL 证书与 Webdriver (Selenium 2.0) 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将个人 SSL 证书与 Webdriver (Selenium 2.0) 一起使用


- Java包名称中单词分隔符的约定是什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01