English 中文(简体)
NUnit Test with WatiN, runs OK from Dev10, but when NUnit started from "C:Program Files (x86)NUnit 2.5.5in et-2.0 unit.exe"
原标题:

I have the following code in an Nunit test ...

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

On right-clicking the project in Dev10(visual studio 10) and choosing [Test With][NUnit 2.5], this test code runs with no problems. I have TestDriven installed. When opening the NUnit from C:Program Files (x86)NUnit 2.5.5in et-2.0 unit.exe" and then opening my test dll, the following text is reported in NUnit Errors and failures

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

As an Aside ... Right-Clicking the source cs file in Dev10 and choosing Run Test, ... works as well. The above test is actually part of TechTalk.SpecFlow 1.3 step, I have NUnit 2.5.5.10112, installed, I have Watin 20.20 installed, I have the following App.config for my test dll
the start angle brackets have been removed ... how do you get xml to show up in

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>

Anyone hit this before ? The NUnit test obviously runs in NUnit 2.5.5 of TestDriven but not when running NUnit 2.5.5 from outside of Dev10 and TestDriven ?

问题回答

Run the test in NUnit as admin. I was running Dev10 as admin so I could attatch and debug w3ww, which was why the TestDriven test was working. As soon as I started running NUnit as admin the COM Server isue issue goess away. What makes it more confusing is that running the hello-world exmaple against google from the Watin site works even though NUnit is not run as admin.
To use NUNit + Watin + against local web server, running NUnit as admin solves the com server exception issue.

Try using RequiresSTA attribute in your test code instead of the configuration file.

I am using MSTest, call Refresh to avoid cached data, this worked for me:

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




相关问题
How do I ignore a test based on another test in NUnit?

I m writing some NUnit tests for database operations. Obviously, if Add() fails, then Get() will fail as well. However, it looks deceiving when both Add() and Get() fail because it looks like there s ...

result.viewname is always string.empty

I cannot seem to return the result.ViewName for use in Nunit tests as it always returns string.empty. I have explicitly set the name of the view inside my controller and would expect the test to pick ...

C#: How to test a basic threaded worker class

I m dipping my toes in how to test multi-threaded stuff, but not quite sure how to get started. I m sure I will figure more stuff out easier if I could just get stuff going, so I was wondering if ...

Selenium Grid with parallel testing using C#/NUnit

I ve got several unit tests written with NUnit that are calling selenium commands. I ve got 2 win2k3 server boxes setup, one is running selenium grid hub along with 2 selenium rc s. The other box is ...

Code coverage with nUnit? [closed]

Is there a way to see the code coverage when using nUnit? I know there s such a feature in Visual Studio, but can you use it with nUnit or only with the built-in vs unit tests?

Unit testing database-dependent Window services

We have a set of services in .NET 3.5C# and WCF. The NUnit tests need the services to be running and listening for requests. The services need an updated SQL database to be ready for connection. ...

TeamCity NUnit test result visualisation

Is there any way to produce visual results of NUnit tests from within TeamCity s "Tests" tab, currently my NAnt script outputs an .xml file of the results using the following task: <nunit2 ...

热门标签