简体   繁体   中英

The type or namespace name 'NUnit' could not be found

I have ac# code.(which is exported from 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"); 
}
}
}

I pasted this code in a console application (visual studio 2008).
After running, I got this errors:

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

What framework should I add to correct this errors?

It seems like you have references missing. From official Selenium docs page :

Add references to the following DLLs: nmock.dll, nunit.core.dll, nunit. framework.dll, ThoughtWorks.Selenium.Core.dll, ThoughtWorks.Selenium.IntegrationTests.dll and ThoughtWorks.Selenium.UnitTests.dll

For your current problem, you need to reference at least NUnit.Framework.dll and Selenium dlls.

Please read the docs page for more info.

Right click on references in the solution explorer and click add reference. You will need to browse for the nunit.framework.dll

您需要添加对 NUNIT dll 的引用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM