sgn
sgn

Reputation: 65

Nothing happend after running test in C# NUnit

at the beginning I want to tell you I'm new in C# automation testing.

I created NUnit Test Project (.NET Core) and I have problem with running test in C# NUnit. When I click on "Run selected test" in Test Explorer then nothing happens. I don't have any error in my Test Explorer. In output I have error System.ArgumentException: Illegal characters in path.

Additionally when I try to run test from commandline ("C:\Tools\NUnit\bin\net35\nunit3-console.exe" C:\Users\MY_USER\source\repos\NUnitTestProject2\NUnitTestProject2.sln) I have Could not load file or assembly nunit.framework error.

The only way to run the test is commandline and dotnet test C:\Users\MY_USER\source\repos\NUnitTestProject2\NUnitTestProject2\NUnitTestProject2.csproj

My NuGet Dependencies:

All the time my Test Explorer looks like this:

Test Explorer screenshot

I tried to change version of my NuGet dependencies.

 public class Tests
    {
        IWebDriver driver;
        [SetUp]
        public void Setup()
        {
            driver = new ChromeDriver("C:/Users/MY_USER/source/repos/NUnitTestProject1/NUnitTestProject1/bin/Debug/netcoreapp2.1/");
        }

        [Test]
        public void Test1()
        {
            driver.Navigate().GoToUrl("https://google.com/");
        }
    }

Upvotes: 1

Views: 1017

Answers (1)

CEH
CEH

Reputation: 5909

I would implement a StartChromeDriver() method to handle starting ChromeDriver correctly. Here's an example:

public IWebDriver StartChromeDriver()
{
            var options = new ChromeOptions();
            options.AddArgument("--disable-extensions");
            options.AddArguments("disable-infobars");
            options.AddArgument("--no-sandbox")       
            driver = new ChromeDriver(options);
            return driver;
}

Then replace the driver = new ChromeDriver call in your [SetUp] method with driver = StartChromeDriver(). The issue may be that you are not providing any ChromeOptions() when initializing your ChromeDriver instance.

Also, as recommended by another user, I would write a simple test to isolate the issue from Selenium vs. NUnit. You can do so like this:

 public class Tests
    {
        // comment out setup method so this Selenium code does not get run.
       // IWebDriver driver;
     //   [SetUp] 
    //    public void Setup()
    //    {
    //        driver = new //ChromeDriver("C:/Users/MY_USER/source/repos/NUnitTestProject1/NUnitTestProject1/bin/Debug/netcoreapp2.1/");
  //      }

        [Test]
        public void Test1()
        {
            Assert.Pass("Passed first test successfully.");
        }
    }

If your test successfully runs without the Selenium / ChromeDriver code, then you know the issue is with Selenium and not NUnit.

Upvotes: 0

Related Questions