Thanks Charlie, I got the point.
For the further reference of readers I'm posting here that what I did to overcome this problem that I was facing.
What I intended to do: I created a SetUpFixture class and initialized the driver and other components that I wanted to use throughout my all test classes containing TestFixture. The method that I followed to achieve it was by inheriting the SetUpFixture class in my all test classes to use the same driver and other components so that I had no need to create and initialize it every time when I add new test class
Problem: problem occurred when the OneTimeTearDown of SetUpFixture class started executing as soon as it finishes the test execution of any one test class but OneTimeSetup did not initialized the components again and control passed to second test class (which was also inheriting the SetUpFixture class) to execute the test methods inside it but as the test cleanup was already processed by OneTimeTearDown there was no instance of driver to run the test methods of second test class and thats where all test cases started failing.
Solution: To overcome this situation what I did
1. I made the SetUpFixture class as an individual class and did not inherit it any other test classes
2. To reuse the drivers and other initialized components in SetupFixture I choose another way. I created a local driver in each test classes and initialized that with the driver created in SetUpFixure class.
3. I have some encapsulated methods in my SetUpFixture class so to reuse those methods I started calling them by prefixing the SetUpFixture class name
Understand It with the code snippet: A: BaseClass
[SetUpFixture]
public class TestSetup
{
public static IWebDriver driver; // created Webdriver instance
public static Actions action;
public static WebDriverWait wait;
public static TopNavigation TopNav = new TopNavigation(); // Encapsulated the other class in TestSetup class to reuse it everywhere
[OneTimeSetUp]
public void testSetup()
{
if (driver == null)
{
//Local Tests
driver = new FirefoxDriver();
//Broswerstack Test
//driver = Browserstack.bs(driver);
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
action = new Actions(driver);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
driver.Manage().Window.Maximize();
}
}
Class B: where I'm reusing this:
[TestFixture]
class SocialIcons //: TestSetup - earlier i was inheritingthe TestSetup class but now i have commented it
{
static IWebDriver driver = TestSetup.driver; // created a local driver and initialized it with the driver initialized in TestSetup class
[Test]
public void SocialIcons_Facebook()
{
TestSetup.TopNav.HoverOverSocialMegaNav(); // using the encapsulated method
TestSetup.action.MoveToElement(driver.FindElement(By.XPath(HomePageOR.SocialIconDropDown)));
driver.FindElement(By.LinkText(HomePageOR.FacebookLink)).Click();
driver.SwitchTo().Window(driver.WindowHandles.Last());
Assert.AreEqual("DK Books", driver.Title); // OR it may be 'Security Check Required'
}
and that's what i did in my all test classes and it works fine for me.
Charlie, please suggest If i have done something wrong here.
Any suggestions will be appreciated.