title: C# equivalent of Java class level fields
body: <p>I'm new(er) to C# than I am to Java and I'm attempting to convert some of my java automation tests into C#.<br>
  My question is about following code:</p>
  
  <pre><code>public class UnitTest1
  { 
      [Test]
      public void loginTest()
      {
          //path variable points to the chrome driver exe bin location
          var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
          //pass the path to our new driver
          var driver = new ChromeDriver(path);
          //then pass the driver to our page object + add IWebdriver as a 
          //param to HomepageClass obj
          var homePage = new HomePage(driver);
  
          homePage.goTo();
      }
  }
  </code></pre>
  
  <p>This code instantiates a new chrome driver and calls a simple goTo method on a homepage object. It also passes the driver to the homepage Object allowing the driver to interact with the page object in other ways.</p>
  
  <p>The way that the code is currently written means that I would have to recreate the local variables for every future Test that I plan to script.
  In a similar fashion to Java, I would like to use something equivalent to fields at class level in order for them to be reused across multiple tests in the class. Can anyone point me in the right direction on how to go about this?</p>
  
  <p>What I've tried so far:</p>
  
  <p>I tried changing the variables to objects at class level, and initializing them in a setup method like so:</p>
  
  <pre><code>public class UnitTest1
  {
      object homePage;
      object path;
      object driver;
  
      [SetUp]
      public void startDriver()
      {
          //path variable points to the chrome driver bin location
          path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
          //pass the path to our new driver
          driver = new ChromeDriver(path);
          //then pass the driver to our page object + add 
          //IWebdriver as a param to HomepageClass obj
          homePage = new HomePage(driver);
      }
  
      [Test]
      public void loginTest()
      {
          homePage.goTo();
      }
  }
  </code></pre>
  
  <p>This generated the following errors, some of which I managed to fix as follows:</p>
  
  <blockquote>
    <p>Argument 1: cannot convert from 'object' to 'OpenQA.Selenium.Chrome.ChromeOptions'</p>
  </blockquote>
  
  <p>State: fixed by: Changing: <code>object path;</code> to <code>ChromeOptions path;</code></p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'string' to 'OpenQA.Selenium.Chrome.ChromeOptions'</p>
  </blockquote>
  
  <p>State: Not yet fixed. This was generated as a result of fixing the first error</p>
  
  <blockquote>
    <p>Argument 1: cannot convert from 'object' to 'OpenQA.Selenium.IWebDriver'</p>
  </blockquote>
  
  <p>State: fixed by : Changing <code>object driver;</code> to <code>IWebdriver driver;</code></p>
  
  <blockquote>
    <p>'object' does not contain a definition for 'goTo' and no extension method 'goTo' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>State: not yet fixed</p>
  
  <p>Any advice appreciated</p>