使用WatiN进行NUnit测试,从Dev10运行正常,但是当NUnit从“C:\ Program Files(x86)\ NUnit 2.5.5 \ bin \ net-2.0 \ nunit.exe”启动时

时间:2010-05-18 12:06:51

标签: nunit watin comexception specflow

我在Nunit测试中有以下代码......

    string url = "";
    url = @"http://localhost/ClientPortalDev/Account/LogOn";
    ieStaticInstanceHelper = new IEStaticInstanceHelper();
    ieStaticInstanceHelper.IE = new IE(url);
    ieStaticInstanceHelper.IE.TextField(Find.ById("UserName")).TypeText("abc");
    ieStaticInstanceHelper.IE.TextField(Find.ById("Password")).TypeText("defg");
    ieStaticInstanceHelper.IE.Button(Find.ById("submit")).Click();
    ieStaticInstanceHelper.IE.Close();

右键单击Dev10(visual studio 10)中的项目并选择[Test With] [NUnit 2.5],此测试代码运行没有问题。我安装了TestDriven。   从C:\ Program Files(x86)\ NUnit 2.5.5 \ bin \ net-2.0 \ nunit.exe“打开NUnit然后打开我的测试dll时,在NUnit错误和失败中报告以下文本

... LoginAsWellKnownUserShouldSucceed:
System.Runtime.InteropServices.COMException : Error HRESULT E_FAIL has been returned from a call to a COM component.

作为Aside ...右键 - 在Dev10中单击源cs文件并选择Run Test,...也可以。   上面的测试实际上是TechTalk.SpecFlow 1.3步骤的一部分,我已经安装了NUnit 2.5.5.10112,我安装了Watin 20.20,   我的测试dll有以下App.config   开始尖括号已被删除...如何让xml显示在

configuration>
  configSections>
    sectionGroup name="NUnit">
      section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
    /sectionGroup>
  /configSections>
  NUnit>
    TestRunner>
      add key="ApartmentState" value="STA" />
    /TestRunner>
  /NUnit>
  appSettings>
    add key="configCheck" value="12345" />
  /appSettings>
/configuration>

之前有人打过这个吗? NUnit测试显然在TestDriven的NUnit 2.5.5中运行,但在Dev10和TestDriven外部运行NUnit 2.5.5时却没有?

3 个答案:

答案 0 :(得分:1)

以管理员身份在NUnit中运行测试。 我作为管理员运行Dev10,所以我可以调试和调试w3ww,这就是TestDriven测试工作的原因。 一旦我开始以管理员身份运行NUnit,COM服务器问题就会消失。 更令人困惑的是,即使NUnit不以管理员身份运行,从Watin站点运行针对谷歌的hello-world exmaple也能正常工作。 要对本地Web服务器使用NUNit + Watin +,以管理员身份运行NUnit可以解决com服务器异常问题。

答案 1 :(得分:0)

尝试在测试代码中使用RequiresSTA属性而不是配置文件。

答案 2 :(得分:0)

我正在使用MSTest,调用Refresh以避免缓存数据,这对我有用:

browser.Refresh();
browser.TextField(Find.ById("username")).TypeText("user");
browser.TextField(Find.ById("password")).TypeText("pass");
browser.Button(Find.ByName("SUBMIT")).Click();