Hello I am have trouble using a method from an Instantiated class. I am rather new to selenium and C#, but here is my code to start...
class 1
[TestClass]
public class UnitTest1
{
Class2 myClass2 = new Class2();
static IWebDriver webDriver;
[AssemblyInitialize]
public static void invokeBrowser(TestContext context)
{
webDriver = new ChromeDriver(@"C:\Selenium\");
}
[TestMethod]
public void TestMethod1()
{
myClass2.RandomMethod();
}
class 2
[TestClass]
public class Class2
{
static IWebDriver webDriver;
public void invokeBrowser(TestContext context)
{
webDriver = new ChromeDriver(@"C:\Selenium\");
}
[TestMethod]
public void RandomMethod()
{
webDriver.Navigate().GoToUrl("http://google.com");
}
}
my error happens in Class1
during my testmethod
that I am using to call the Randommethod
from my other class
Message: Test method CheckRequest.UnitTest1.TestMethod1 threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
I have been struggling with this error for a while and I just dont understand what I am doing wrong. The only object that I am setting is my webdriver
. Is the issue that I am creating two different webdriver objects? Thanks for your time, and any help is much appreciated.