title: Using a method from one test in another
body: <p>This seems simple, but for some reason I've not got it to work.</p>
  
  <p>I'm using Selenium with Nunit.</p>
  
  <p>I have one class called 'Registration_Test' in which I have a method named 'completeRegistrationForm()' which does as described.</p>
  
  <p>I would like this method to be available for me to call in a number of different tests.</p>
  
  <p>This is what I have in my second test.</p>
  
  <pre><code>Registration_Test reg = new Registration_Test();
  reg.completeRegistrationForm();
  </code></pre>
  
  <p>This compiles happily but when I run it in Nunit I get the following:</p>
  
  <pre><code>SeleniumTests.Check_Links.Check_linksTest:
  System.NullReferenceException : Object reference not set to an instance of an object.
  </code></pre>
  
  <p>and it indicates that reg.completeRegistrationForm(); line is the culprit.</p>
  
  <p>Appreciate any help you can offer.</p>
  
  <p>Here are my two tests:</p>
  
  <p>Registration-test.cs</p>
  
  <pre><code>namespace SeleniumTests
  {
  [TestFixture]
  public class Registration_Test
  {
      private ISelenium selenium;
      private StringBuilder verificationErrors;
  
      [SetUp]
      public void SetupTest()
      {
          selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://custom-creative-404-dropbox:8080/");
          selenium.Start();
          verificationErrors = new StringBuilder();
      }
  
      [TearDown]
      public void TeardownTest()
      {
          try
          {
              selenium.Stop();
          }
          catch (Exception)
          {
              // Ignore errors if unable to close the browser
              Console.Write("Unable to Stop Selenium and/or close the browser");
          }
          Assert.AreEqual("", verificationErrors.ToString());
      }
  
      [Test]
      public void Registration()
      {
  
          completeRegistrationForm();
  
          //back to home page.
          selenium.Click("link=Home");
          selenium.WaitForPageToLoad("30000");
      }
  
  
      public void completeRegistrationForm()
      {
          selenium.Open("/");
          selenium.Click("link=Register");
          selenium.WaitForPageToLoad("30000");
  
          string uniqueVal = selenium.GetEval("\"AutomatedTest\" + (new Date().getDate()) + (new Date().getTime())");
          //use moment instead.
  
          selenium.Type("id=RegistrationForm_TxtName", uniqueVal);
  
          selenium.Type("id=RegistrationForm_TxtUserName", uniqueVal + "@creative-404.com");
          selenium.Type("id=RegistrationForm_TxtPassword", uniqueVal);
          selenium.Type("id=RegistrationForm_TxtRePassword", uniqueVal);
          selenium.Click("id=RegistrationForm_Button1");
          selenium.WaitForPageToLoad("30000");
  
          for (int second = 0; ; second++)
          {
              if (second &gt;= 60) Assert.Fail("timeout");
              try
              {
                  if (selenium.IsTextPresent("Registration was successful!")) break;
              }
              catch (Exception)
              {
                  Console.Write("Unable to find the Registration successful message. Something has gone wrong..");
              }
              Thread.Sleep(1000);
          }
      }
  
  }
  }
  </code></pre>
  
  <p>and Test-Links.cs (this test was made really just to test this out)</p>
  
  <pre><code>namespace SeleniumTests
  {
  [TestFixture]
  public class Check_Links
  {
      private ISelenium selenium;
      private StringBuilder verificationErrors;
  
      [SetUp]
      public void SetupTest()
      {
          selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://custom-creative-404-dropbox:8080/");
          selenium.Start();
          verificationErrors = new StringBuilder();
      }
  
      [TearDown]
      public void TeardownTest()
      {
          try
          {
              selenium.Stop();
          }
          catch (Exception)
          {
              // Ignore errors if unable to close the browser
          }
          Assert.AreEqual("", verificationErrors.ToString());
      }
  
      [Test]
      public void Check_linksTest()
      {
          Registration_Test reg = new Registration_Test();
          reg.completeRegistrationForm();
  
          selenium.Open("/home.aspx");
          selenium.Click("link=Home");
          selenium.WaitForPageToLoad("30000");
          selenium.Click("link=Gallery");
          selenium.WaitForPageToLoad("30000");
      }
  }
  }
  </code></pre>