0

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();
        }
    }
}

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I am following a tutorial on the web. executeautomation.com/blog/using-nunit-with-selenium-c The guy has shown console app in the video.
@Aruba: yes, but in the video you just linked you can see the guy running the test case from the Test Explorer window with the "Run Selected Test" command. In your video you aren't doing that. Take a look again and the tutorial video and than take a look at your video and see there's a difference in how he starts executing the unit test(from Test explorer by using "Run Selected Test") and how you do it.
Thank you for pointing out my mistake. I was running the test wrong way.
1

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

1 Comment

Thank you @sptramp. I found Microsoft.Net.Test.sdk present already in my case, but I was apparently missing Nunit3TestAdapter, after which my test actually started running!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.