Reputation: 65
I have a global base class in my solution that all of my tests inherit from, this class contain public IWebDriver property. My project base class inherit from the solution base class and initialize the IWebDriver property. My stepDeffinition class inherit from project base class and the beforeScenario property call the project base class TestInitialize that initialize the IWebDriver.
The global base class have TestCleanup tag to close the IWebDriver session but it uses static method that one of the properties of the method it the IWebDriver, when the static method is called the IWebDriver value is null (inside the method), although that when we passed it it wasn't.
Why my static method sees it as null??
[TestClass]
public class SolutionTestBase
{
public IWebDriver WebDriver { get; protected set; }
[TestCleanup]
public void SubBaseTestCleanup()
{
if (WebDriver != null)
{
WebDriverFactory.QuitFromWebDriver(WebDriver, TestSettings);
}
}
}
[TestClass]
public class ProjectBaseTest : SolutionTestBase
{
public void Initialize()
{
WebDriver = WebDriverFactory.GetDriverFromConfig(currBrowser.Name, TestContext);
}
}
[Binding]
public class StepDefinitions : ProjectBaseTest
{
[BeforeScenario("ConsoleAnalytics"), DataSource(BrowsersRef)]
public void BeforeAnalyticsScenario()
{
Initialize();
}
}
public class WebDriverFactory
{
public static void QuitFromWebDriver(IWebDriver webDrivers, TestSettings testSettings, int milliSeconds = 200)
{
if (/*Some Code*/)
{
/*
*
* Some Code
* */
}
else if (testSettings == TestSettings.Local)
{
webDrivers.Quit();
}
}
}
Upvotes: 2
Views: 729
Reputation: 32936
You shouldn't mix your test setup/cleanup infrastructure between specflow and mstest. SpecFlow is a test generation tool. It will generate the [Test]
and [TestCleanup]
methods for you and so your classes should not use them.
If you want things to happen after your tests then you should use the SpecFlow infrastructure to do this ie use the [AfterScenario]
tag in specflow
Upvotes: 1