An exception occurred while test discoverer 'NUnit3TestDiscoverer' was loading tests

2.8k Views Asked by At

I built a simple NUnit Framework to run a Selenium WebDriver C# Test in Visual Studio 2015.

I've installed the NUnit v3.12, Selenium WebDriver v3.141, NUnit3TestAdapter v3.17 extensions.

If I'm unable to download the Browser Driver why am I'm getting this Error:

******------ Discover test started ------
An exception occurred while test discoverer 'NUnit3TestDiscoverer' was loading tests. Exception: Object reference not set to an instance of an object.
========== Discover test finished: 0 found (0:00:03.1151069) ==========******

Below code trying to navigate to web page and login to application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;


namespace eMPWR_TEST_AUTOMATION
{

    [TestFixture] // This is your Test Suite containing all you below TESTS ([Test])

    public class eMPWR_SmokeTests
    {
        private IWebDriver driver;
        private StringBuilder verificationErrors;
        private String baseURL;
        private bool acceptNextAlert = true;

        [SetUp]
        public void SetUpTests()
        {
            driver = new FirefoxDriver();
            baseURL = "https://va--fasaoadev.my.salesforce.com";
            verificationErrors = new StringBuilder();
        }

        [TearDown]
        public void TearDownTests()
        {
            try
            {
                driver.Quit();
            }
            catch (Exception)
            {
                //ignore errors if unable to close the browser
            }

            Assert.AreEqual("", verificationErrors.ToString());
        }

        [TestCase("UserName1", "Password1")] // Using 3 scenarios instead of below variables
        [TestCase("UserName2", "Password2")]
        [TestCase("UserName3", "Password3")]
        public void eMPWR_Login(string UserName, string Password)
        {
            //String UserName = "UserName1";
            //String Password = "Password1";
            String Url = "www.login.Salesforce.com";

            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl(Url);
            driver.FindElement(By.Id("UserName")).SendKeys(UserName);
            driver.FindElement(By.Id("Password")).SendKeys(Password);
            driver.FindElement(By.Id("Login")).Click();

            String ExpectedData = "Salesforce";
            String ActualData = "Sales Force";

            Assert.That(ExpectedData, Is.EqualTo(ActualData)); // from NUnit Framework

            driver.Close();
        }

        [Test]
        public void eMPWR_SearchSSN()
        {
            string URL = "https://va--fasaoadev.my.salesforce.com";
            string FN = "John";
            string LN = "Doe";
            string Email = "[email protected]";
            string PWD = "F00tB@11";

            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl(URL);
            driver.FindElement(By.CssSelector("input.submitbutn")).Click();
            driver.FindElement(By.Id("ctl00_MainContent.txtFirstName")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent.txtFirstName")).SendKeys(FN);
            driver.FindElement(By.Id("ctl00_MainContent.txtLastName")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent.txtLastName")).SendKeys(LN);
            driver.FindElement(By.Id("ctl00_MainContent.txtEmail")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent.txtEmail")).SendKeys(Email);
            driver.FindElement(By.Id("ctl00_MainContent.txtVerifyPassword")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent.txtVerifyPassword")).SendKeys(PWD);
            driver.FindElement(By.CssSelector("input.submitbutn")).Click();

            Assert.AreEqual("Login Successful", 
            driver.FindElement(By.Id("ctl00_MainContentlblTransactionResult")).Text);
        }
    }
}

2

There are 2 best solutions below

0
On

Taken from https://www.stevefenton.co.uk/2018/02/nunit-exception-occurred-test-discoverer-loading-tests/:

  1. Close Visual Studio.
  2. Delete the cache folder at the following location: C:\Users\Your.Name\AppData\Local\Temp\VisualStudioTestExplorerExtensions\NUnit3TestAdapter.version
  3. Re-open Visual Studio.
  4. Build your project. The tests should now show up in the Test Explorer Window.

It worked for me!

0
On

I closed my Visual Studio 2015-->Run as Administrator-->Build the Solution. It should solve your problem from then on. Make sure the nunit.framework reference version of latest(or 3.13.1.0).