【发布时间】:2011-07-31 11:38:45
【问题描述】:
我正在测试一个需要个人 SSL 证书才能执行某些操作(例如登录)的网站。
我有一个使用代理设置的 Webdriver (Selenium 2.0) 测试:
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 证书,因此无法连接到登录服务。
我搜索了不同的代理解决方案,发现了这个:
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
所以我将它添加到我的代码中,但它似乎没有达到我想要的效果。我想我正在寻找一种方法来告诉 WebDriver 我的 ssl 证书在 x 目录中,请在访问此站点时使用它。有人知道怎么做吗?
我的测试代码是:
@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);
}
【问题讨论】:
-
奇怪的是,当我运行测试时,我中途停止了它并访问了 Firefox -> Preferences -> Advanced -> Encyption 并选择了查看证书的选项...浏览器崩溃了我。