3

I am getting lots of CS0246 Code error messages in Visual Studio after trying to run the Selenium code below. I have chosen the ASP.Net Core file to programme the code in.

The file is called LoginTest.cs. Here is the code:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace Tests
{
    [TestFixture]
    class LoginTest
    {
        IWebDriver Driver;

        [SetUp]
        public void SetUp()
        {
            Driver = new FirefoxDriver();
        }

        [TearDown]
        public void TearDown()
        {
            Driver.Quit();
        }

        [Test]
        public void ValidAccount()
        {
            Driver.Navigate().GoToUrl("http://the-internet.herokuapp.com/login");
            Driver.FindElement(By.Id("username")).SendKeys("tomsmith");
            Driver.FindElement(By.Id("password")).SendKeys("SuperSecretPassword!");
            Driver.FindElement(By.CssSelector("button")).Click();
        }
    }
}

The error messages I am getting are:

CS0246 The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'OpenQA' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'OpenQA' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'TestFixtureAttribute' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'TestFixture' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'IWebDriver' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'SetUpAttribute' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'SetUp' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'TearDownAttribute' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'TearDown' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

CS0246 The type or namespace name 'FirefoxDriver' could not be found (are you missing a using directive or an assembly reference?)

CS0103 The name 'By' does not exist in the current context Tests

I have downloaded NUnit 3 Test Adapter (per https://stackoverflow.com/questions/47375788/install-nunit-with-visual-studio-2017).

As I have also got HTTP Error 502.5 - Process Failure error on my localhost, I have trusted the IIS certificate (per https://blogs.msdn.microsoft.com/robert_mcmurray/2013/11/15/how-to-trust-the-iis-express-self-signed-certificate/)

Lastly, I did a dotnet restore as per https://developercommunity.visualstudio.com/content/problem/27820/cs0246-the-type-or-namespace-name-system-could-not.html

Nothing I have done has stopped these error messages. As I am new to Selenium and I am running this code file from a tutorial on the basics of Selenium, I could not tell what the problem is. Does anyone here have any idea what I could be doing wrong or what I need to do to fix the problem?

UPDATE 1:

Thanks, Kate. I have Nunit under the References node but not the OpenQA.Selenium so I tried to look for it in Manage NuGet Packages but it is not found. What I do have already are Selenium.Webdriver and Selenium.Support. Any idea why OpenQA.Selenium could not be found under Browse? Thanks in advance.

UPDATE 2:

I managed to get rid of the error messages after adding in packages Selenium.WebDriver, Selenium.Support and Selenium.WebDriverBackedSelenium but when running am now getting the error message that 'A project with an Output Type of Class Library' cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project'. I am trying to understand how to do this exactly. Any clear explanation is appreciated.

UPDATE 3:

Finally managed to get rid of the error message above too. I just had to install Selenium.Firefox.WebDriver package. Thanks for the help offered

0

1 Answer 1

1

Your first two errors are causing the rest of the errors.

The first thing you need to do is make sure that your project (not your solution) has a reference to NUnit and to OpenQA.

In Visual Studio 2017 and higher, open the Solution Explorer, then in your project expand the References node, then the NuGet node. You should see both NUnit and OpenQA.Selenium listed. If not, right-click and select Manage NuGet Packages... to open NuGet for the project and install both. That should fix most of the problems you are having and will make it easier to deal with other issues.

You can find more information on handling references in projects here.

If the correct references are in place, you may need to tweak your settings to ensure that the Selenium and NUnit dll files are copied to your run directory. You can find information on how to do that from the link I referenced above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.