如何解决在WebdriverSelenium 2.0中使用个人SSL证书
Webdriver没有用于添加个人证书的内置机制。
如果您使用的是firefox,我发现这样做的唯一方法是创建一个firefox配置文件并将证书添加到其中。然后,您可以在运行测试时重用配置文件,或者这是我的首选选项,获取cert8.db和key3.db文件,并将它们添加到webdriver在运行时创建的配置文件中。
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 so you should be able to do this same thing.
解决方法
我正在测试一个网站,该网站需要个人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);
}
谢谢,Beccy
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。