title: How to instantiate object of a Factorymethod pattern and and use that method in different classes?
body: <p>This is my BrowserRunnerFactory.cs where I have defined to choose chrome and Firefox browser:</p>
  
  <pre><code>public class BrowserRunnerFactory
  {
      public static IBrowserInterface InitiateBrowser(BrowserType BrowserType)
      {
  
          switch (BrowserType)
          {
              case BrowserType.Chrome:
                  return new ChromeRunner();
              case BrowserType.Firefox:
              default:
                  return new FirefoxRunner();
          }
      }
  </code></pre>
  
  <p>I have called it and defined two different filed browser and driver in a calss baseInitializer.cs:</p>
  
  <pre><code>public void GetDriver()
      {
        if (browser is null)
          { 
              browser = 
              BrowserRunnerFactory.InitiateBrowser(BrowserType.Chrome);
              driver = browser.Driver;
          }
      }
  </code></pre>
  
  <p>I'm trying to create automated testing and with <strong>browser</strong> I am trying to call chrome browser. And with the <strong>driver</strong> field I want to manipulate the selenium properties like driver.Manage(), driver.FindElement(By.Id()), driver.Close(),* etc.
  <hr>
  So in the baseInitializer.cs class it is working fine. I am getting the value of both of the field browser and driver.
  The <strong>browser</strong> filed should be called only once in the baseInitializer class such that the chrome Browser opens up to run all UI Automated Tests. <br><hr>
  But when I try to call driver from a separate class say ClientTab.cs where I am trying to test some tab of a page like shown below:</p>
  
  <pre><code>BaseInitializer baseinItializer = new Baseinitializer();
  public IWebDriver driver = null;
   public bool TabIsOpen()
      {
          driver = baseInitializer.driver; 
          driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(1);
          try
          {
              driver.FindElement(By.XPath(_configModel.NewRepository)).Click();
              return true;
                         }
          catch (Exception e)
          {
              _logger.Log("Error occured while looking for CLientTabId:" + 
               e.Message);
              return false;
          }
          finally
          {
              driver.SwitchTo().DefaultContent();
          }
      }
  </code></pre>
  
  <p>After I run the test I will get the NullReferenceException : Object reference not set to an instance of an object.
  While Debugging I find that the driver is null. While I want the driver as defined in the GetDriver method</p>
  
  <pre><code>driver = browser.Driver()
  </code></pre>
  
  <p>I tried this design pattern for the first time and also I'm a beginner of in C#. So any feedback, as well as suggestion regarding my coding practices, would be so helpful.</p>