类型或命名空间名称“NUnit”无法找到

22

我有一个C#代码(它是从Selenium IDE导出的)。

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{
[TestFixture]
public class csharp
{
private ISelenium selenium;
private StringBuilder verificationErrors;

[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:1924/");
selenium.Start();
verificationErrors = new StringBuilder();
}

[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop(); 
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}

[Test]
public void TheCsharpTest()
{
        selenium.Open("/cookie/Default.aspx");
        selenium.Type("id=TextBox1", "ranadheer");
        selenium.Type("id=TextBox2", "SE");
        selenium.Type("id=TextBox3", "hyderabad");
        selenium.Click("id=Button1");
        selenium.WaitForPageToLoad("30000");
        selenium.Click("id=Button2");
        selenium.WaitForPageToLoad("30000"); 
}
}
}

我将这段代码粘贴到了一个控制台应用程序(Visual Studio 2008)中。运行后,我遇到了以下错误:

The type or namespace name 'NUnit' could not be found.
The type or namespace name 'TestFixture' could not be found
The type or namespace name 'ISelenium' could not be found
The type or namespace name 'SetUpAttribute' could not be found

为了解决这些错误,我需要添加哪个框架?

3个回答

16

看起来你缺少一些引用。在官方的Selenium文档页面中写道:

添加以下DLL引用:nmock.dll、nunit.core.dll、nunit.framework.dll、ThoughtWorks.Selenium.Core.dll、ThoughtWorks.Selenium.IntegrationTests.dll和ThoughtWorks.Selenium.UnitTests.dll。

对于你当前的问题,你需要引用至少NUnit.Framework.dll和Selenium dlls。

请阅读文档页面获取更多信息。


9
在解决方案资源管理器中右键单击“引用”,然后单击“添加引用”。 您需要浏览 nunit.framework.dll。

2
您需要添加对NUNIT dll的引用。

2
该dll名为nunit.framework.dll,可从NUNIT网站下载。 - TGH
你还需要 Selenium 的 dll 文件 (ThoughtWorks.Selenium.Core.dll)。 - TGH

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接