Aruba
Aruba

Reputation: 17

Test execution not running with NUnit, Selenium and C#

I am trying to learn and setup NUnit with Selenium in C#.

The following are included in my framework

  1. Visual Studio Community 2017
  2. NUnit 3 Test Adapter, ver 3.9.0.0
  3. NUnit v3.9.0
  4. Selenium Webdriver 3.7.0
  5. Selenium Webdriver IEDriver v3.7.0

When I run my code nothing happens. The test explorer does not show any execution. I am unable to resolve this.

Check this video for the issue: https://screencast-o-matic.com/watch/cbX3rQ2t6Z

Below is the code

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestTut
{

    class Program
    {
        //Declaring Internet Explorer driver
        IWebDriver driver = new InternetExplorerDriver();

        static void Main(string[] args)
        {
        }

        [SetUp]
        public void Initialize()
        {
            // Navigate to test URL
            driver.Navigate().GoToUrl("http://www.google.com/");
        }

        [Test]
        public void ExecuteTest()
        {
            // Enter in Google search
            IWebElement element = driver.FindElement(By.Name("q"));

            // Perform action
            element.SendKeys("This is a test");
            Console.WriteLine("Type the text in search box");
        }

        [TearDown]
        public void CloseDriver()
        {
            // Close the browser
            driver.Close();
        }
    }
}

Upvotes: 0

Views: 4223

Answers (2)

sptramp
sptramp

Reputation: 946

I was having the same issue and solved it by installing some missing NuGet Packages:

  1. Nunit.ConsoleRunner
  2. Nunit3TestAdapter
  3. Microsoft.Net.Test.sdk

Upvotes: 1

Vladimir Lazar
Vladimir Lazar

Reputation: 329

Hmm... maybe I'm wrong on this but shouldn't you start running it as a unit test from test explorer or whatever its name is?

The problem might be that you're running it as a console application and since your Main method is empty it of course doesn't do anything.

Upvotes: 1

Related Questions