在Webdriver中使用个人SSL证书(Selenium 2.0) [英] Using Personal SSL certificates with Webdriver (Selenium 2.0)

查看:299
本文介绍了在Webdriver中使用个人SSL证书(Selenium 2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个需要个人SSL证书才能执行某些操作的网站,例如登录。



我有一个Webdriver(Selenium 2.0)测试我已经设置了代理:

 代理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(),'登录')]))。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

解决方案

Webdriver没有内置的机制来添加个人证书。



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



我不确定你是如何在java中做到这一点的,但是在ruby中我覆盖了FirefoxProfile的layout_on_disk方法来添加我需要的额外文件。 Java有 同一个班级 所以你应该能够做同样的事情。


I am testing a website which requires personal SSL certificates in order to do certain things, such as sign-in.

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);

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);

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?

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

解决方案

Webdriver has no built in mechanism for adding a personal cert.

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.

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.

这篇关于在Webdriver中使用个人SSL证书(Selenium 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆