【问题标题】:The type or namespace name 'NUnit' could not be found找不到类型或命名空间名称“NUnit”
【发布时间】:2012-04-10 15:48:04
【问题描述】:

我有一个 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)。
运行后,我得到了这个错误:

找不到类型或命名空间名称“NUnit”。
找不到类型或命名空间名称“TestFixture”
找不到类型或命名空间名称“ISelenium”
找不到类型或命名空间名称“SetUpAttribute”

我应该添加什么框架来纠正这个错误?

【问题讨论】:

    标签: c# frameworks selenium


    【解决方案1】:

    您似乎缺少参考资料。来自官方Selenium docs page

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

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

    请阅读文档页面了解更多信息。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您需要添加对 NUNIT dll 的引用

        【讨论】:

        • 该dll名为nunit.framework.dll,可以从NUNIT网站下载
        • 您还需要 Selenium dll (ThoughtWorks.Selenium.Core.dll)
        猜你喜欢
        • 2021-08-19
        • 1970-01-01
        • 1970-01-01
        • 2017-07-12
        • 2011-05-13
        • 2013-03-25
        • 2012-06-19
        • 2017-11-29
        相关资源
        最近更新 更多