I'm a beginner in C#. I get a Null Reference Exception when I'm instantiating a class in NUnit programming. I have two separate class- a global library and the main program. I want to use the instantiated class(globalLib) both in setup and test. The exception error is because I have set the globalLib as null. How do I correct this?. How should the class be instantiated so that it can be used in setup and test? I have given the code below. Any help appreciated. Thanks.
My code:
Class 1:
[TestFixture]
public class LandForSale
{
private IWebDriver driver = null;
GlobalLibrary globalLib = null;
[SetUp]
public void OpenBrowser()
{
globalLib = new GlobalLibrary(driver);
globalLib.StartDriver();
}
[Test]
public void TestScenario()
{
string[] setofitems = { "Residential", "Commercial" };
foreach (string item in setofitems)
{
globalLib.OpenUrl();
globalLib.Search();
etc...
}
}
}
}
Class 2:
public class GlobalLibrary
{
IWebDriver driver = null;
public GlobalLibrary(IWebDriver driver)
{
this.driver = driver;
}
public IWebDriver StartDriver()
{
driver = new FirefoxDriver();
return driver;
}
public void OpenUrl()
{
driver.Navigate().GoToUrl("http://www.auction.com/");
driver.Manage().Window.Maximize();
}
public void Search()...
}
}