0
votes

Setup and Teardown attribute methods not getting invoked using Nunit-3.11 and Visual Studio - 2017

using GV5Base;

namespace DBPAutomation.Test
{
    [TestClass]
    public class Training
    {
        public IWebDriver driver;

        // initializing the driver and open the browser 
        [SetUp]
        public void BrowserInitialize()
        {
            Base bs = new Base();
            bs.SetBrowser("Chrome");
            driver = bs.driver;

        }
    }
}

namespace Base
{
    [TestClass]
    class Base
    {
        public IWebDriver driver;
        public string TestUrl = "http://google.com";

        public void SetBrowser(string browser)
        {
            if(browser == "Chrome")
            {
                this.driver = new ChromeDriver();
                driver.Navigate().GoToUrl(TestUrl); 
            }
            else if(browser == "IE")
            {
                IWebDriver driver = new InternetExplorerDriver();
                driver.Navigate().GoToUrl(TestUrl);

            }
        }

On execution getting System.NullReferenceException: Object reference not set to an instance of an object. Because Setup method is not getting invoked Also tried with OneTimeSetup and OneTimeTeardown even these options not working

1

1 Answers

0
votes

You use TestClass which is from MSTest, so it don't know how to use SetUp attribute and others. You should remove TestClass attribute or replace it with TestFixture. TestFixture attribute it is not required if NUnit detects a method, which has attribute like for example Test, TestCase, TestCaseSource.