自动化选择数字证书对话框 [英] Automating the Choose a digital certificate dialog

查看:259
本文介绍了自动化选择数字证书对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的华廷(2.0.10.928)用C#和Visual Studio 2008来测试SSL安全网站,需要证书。当您导航到主页一个选择一个数字证书显示对话框,要求您选择一个有效的证书,然后单击确定按钮。

I am using WatiN (2.0.10.928) with C# and Visual Studio 2008 to test a SSL secured website that requires a certificate. When you navigate to the homepage a "Choose a digital certificate" dialog is displayed and requires that you select a valid certificate and click the 'OK' button.

我正在寻找一种方式来自动证书选择,这样在每次执行新的测试夹具或时间(和我的浏览器重新启动)我没有手动干涉的自动化测试,并选择证书。我一直利用各种对话华廷处理类尝试,甚至看着使用Win32 API自动执行此,但没有多少运气。

I'm looking for a way to automate the certificate selection so that every time a new test or fixture is executed (and my browser restarts) I don't have to manually interfere with the automated test and select the certificate. I've tried using various WatiN Dialog Handler classes and even looked into using the Win32 API to automate this but haven't had much luck.

我终于找到了解决方案,但它增加了一个依赖于溶液(第三方库调用AutoIt的)。由于该解决方案是不理想,但没有工作,是我能找到的最好的,我会发布解决方案,它标志着作为答案,但我还在寻找一个'开箱即用'华廷解这是我的code和测试夹具的其余部分更一致。

I finally found a solution but its adds another dependency to the solution (a third party library called AutoIT). Since this solution isn't ideal but does work and is the best I could find, I will post the solution and mark it as the answer but I am still looking for an 'out of the box' WatiN solution that is more consistent with the rest of my code and test fixtures.

感谢您的答复!

推荐答案

在我的情况我都只有一个证书附加,所以我拿起一个,目前唯一的就行了,所以我真的很简单的 DialogHandler中此 - 它只是点击按钮,如果它罐处理对话框:

In my situation I have exactly one certificate attached, so I have to pick up the one and only existing on the list, so I have really simple DialogHandler for this - it only clicks on the button if it cans handle the dialog:

public class CertificateChoosingHandler : BaseDialogHandler
{
    public override bool HandleDialog(Window window)
    {
        new WinButton(1, window.Hwnd).Click();
        return true;
    }

    public override bool CanHandleDialog(Window window)
    {
        return window.StyleInHex == "94C808CC";
    }
} 

AFAIR该解决方案将不会在Windows 7中运行。

AFAIR this solution won't work in Windows 7.

编辑:我忘了一些有用的东西。当我发现这个解决方案不是在Windows 7中的工作,我在自定义级别的地方发现了IE浏览器Internet选项非常有趣的选项:不提示进行客户证书选择时,没有证书或只有一个证书。所以,我已经加入我的网站到受信任的网站和编辑的设置,并没有必要现在对我来说,使用这种即使出现 DialogHandler中,但它仍然可以使用任何对话。如果它是不明确的,是我写的,这里是如何在互联网上证启用提示资源管理器,以显示证书对话框。

I forgot about something useful. When I found that this solution is not working in Windows 7, I discovered very interesting option in IE Internet Options somewhere in "Custom Level": Don’t prompt for client certificate selection when no certificates or only one certificate exists. So I have added my site to trusted sites and edited settings, and there is no need now for me to use this DialogHandler, but it still can be used even if no dialog appears. If it is not clear, what I wrote, here is how to Enable Prompt for Certificate in Internet Explorer to show certificate dialog.

这篇关于自动化选择数字证书对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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