title: How to access TestRunParameters within RunSettings file
body: <p>Reading through <a href="https://msdn.microsoft.com/en-us/library/jj635153.aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/jj635153.aspx</a>  I have created a <code>.RunSettings</code> files with a few parameters similar to the example:</p>
  
  <pre><code>  &lt;TestRunParameters&gt;
      &lt;Parameter name="webAppUrl" value="http://localhost" /&gt;
      &lt;Parameter name="webAppUserName" value="Admin" /&gt;
      &lt;Parameter name="webAppPassword" value="Password" /&gt;
    &lt;/TestRunParameters&gt;
  </code></pre>
  
  <p>I plan on having a <code>.RunSettings</code> file for each of our environments with appropriate URLs and credentials for running a CodedUI test on the specified RunSettings file's environment.</p>
  
  <p>I can see that from command line to reference the Settings file I can run:</p>
  
  <pre><code>vstest.console myTestDll.dll /Settings:Local.RunSettings /Logger:trx
  vstest.console myTestDll.dll /Settings:QA.RunSettings /Logger:trx
  </code></pre>
  
  <p>etc...</p>
  
  <p>But I don't see any way that calls out how to actually utilize the <code>TestRunParameters</code> from within the codedUI test.</p>
  
  <p>What I would like to do is set up test initializers that use the <code>TestRunParameters</code> to determine where to log in, and what credentials to use.  Something like this:</p>
  
  <pre><code>[TestInitialize()]
  public void MyTestInitialize()
  {
  
      // I'm unsure how to grab the RunSettings.TestRunParameters below
      string entryUrl = ""; // TestRunParameters.webAppUrl
      string userName = ""; // TestRunParameters.webAppUserName
      string password = ""; // TestRunParameters.webAppPassword
  
      LoginToPage(entryUrl, userName, password);
  }
  
  public void LoginToPage(string entryUrl, string userName, string password)
  {
      // Implementation
  }
  </code></pre>
  
  <p>Information on how to reference the <code>TestRunParameters</code> is greatly appreciated!</p>
  
  <p>EDIT</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Summary description for CodedUITest1
  /// &lt;/summary&gt;
  [CodedUITest]
  public class CodedUITest1
  {
  
      public static string UserName = string.Empty;
  
      [ClassInitialize]
      public static void TestClassInitialize(TestContext context)
      {
          UserName = context.Properties["webAppUserName"].ToString();
          Console.WriteLine(UserName);
      }
  
      [TestMethod]
      public void CodedUITestMethod1()
      {
          this.UIMap.RecordedMethod1();
          // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
      }
  
      // Rest of the default class - TestContext instantiation, UI map instantiation, etc
  }
  </code></pre>
  
  <p>The exception I'm getting when running:</p>
  
  <p>NullReference Exception</p>
  
  <p><a href="https://i.stack.imgur.com/OqOi9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OqOi9.png" alt="enter image description here"></a></p>
  
  <p>@williamfalconeruk I have updated my test class as above, but I am still getting the same error, any idea what I'm doing wrong?</p>