在Webdriver中使用个人SSL证书(Selenium 2.0)

Bec*_*ccy 7 java selenium webdriver

我正在测试一个需要个人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);
Run Code Online (Sandbox Code Playgroud)

这将很好地访问主页.然后,测试点击登录按钮,输入正确的凭据并单击提交.此时浏览器进入加载状态,我假设是因为我的身边缺少SSL证书,因此无法连接到登录服务.

我搜索了不同的代理解决方案,发现了这个:

    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(true);
Run Code Online (Sandbox Code Playgroud)

所以我把它添加到我的代码中,但它似乎没有做我想要的.我想我正在寻找一种方法告诉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);
}
Run Code Online (Sandbox Code Playgroud)

谢谢,贝西

Der*_*ins 5

Webdriver没有用于添加个人证书的内置机制.

如果您使用的是firefox,我发现这样做的唯一方法是创建一个firefox配置文件并将证书添加到它.然后,您可以在运行测试时重用该配置文件,这是我的首选选项,请获取cert8.db和key3.db文件,并将它们添加到webdriver在运行时创建的配置文件中.

我不确定你是如何在java中做到这一点的,但是在ruby中我覆盖了FirefoxProfile的layout_on_disk方法来添加我需要的额外文件.Java具有相同的类,因此您应该能够做同样的事情.