title: Variables from properties.file not being passed - TestNG - WebDriver Test
body: <p>I am using Webdriver + TestNG.  I created a class where you can run any test with the browser of your choice just by using the method below where you enter which browser to run and what test to run as your variables. Now I am trying to feed my "browser" variable and "test" variable from a properties file.  When I run it I just get a Pass but nothing happens.  If I manually enter the variables it works fine. How come it wont take the values from the properties file?  If I do a print - it prints the correct value...</p>
  
  <p>This is the contents of the properties file:   </p>
  
  <p>browser="BROWSER GOES HERE"</p>
  
  <p>test="TEST GOES HERE"</p>
  
  <p>Here is my method to run the test:</p>
  
  <pre><code>@Test
          public void runTest() throws IOException {
              Properties prop = new Properties();
              prop.load(new FileInputStream(
                      "path\\test.properties"));
              localBrowser(prop.getProperty("browser"));
              masterTest(driver, prop.getProperty("test"));
          }
  </code></pre>
  
  <hr>
  
  <p>Here is a sandbox example of my test:</p>
  
  <p>If I put the variables in myself the browser will open and execute the test.  If I use the property loader it will just print the variables but will not run the test. Here is a sandbox example so you can try it.</p>
  
  <p>Package Structure:  </p>
  
  <p>-src/test/java<br>
  --SandboxTest<br>
  -src/test/resources<br>
  --test.properties  </p>
  
  <p>Properties File example: </p>
  
  <p>browser=firefox<br>
  test=test1  </p>
  
  <p>Class example:  </p>
  
  <p>public class SandboxTest {</p>
  
  <pre><code>private WebDriver driver;
  InputStream input = null;
  Properties prop = new Properties();
  
  @Test
  public void runTest() throws FileNotFoundException, IOException {
          input = new FileInputStream(
                  (new File(
                      "C:INSERT_PATH_HERE\\test.properties")));
          prop.load(input);
              //This doesnt run the test
          System.out.println(prop.getProperty("browser"));
          System.out.println(prop.getProperty("test"));
          localBrowser(prop.getProperty("browser"));
          masterTest(driver, prop.getProperty("test"));
          /* 
           * This works
                   * localBrowser("firefox");
           * masterTest(driver, "test1");
           */
  
  
  }
  
  public void localBrowser(String browser) {
      if (browser == "firefox") {
          driver = new FirefoxDriver();
      } else if (browser == "chrome") {
          System.setProperty("webdriver.chrome.driver",
                  "C:\\INSERT_PATH_HERE\\chromedriver.exe");
          driver = new ChromeDriver();
      } else if (browser == "ie") {
          System.setProperty("webdriver.ie.driver",
                  "C:\\INSERT_PATH_HERE\\IEDriverServer.exe");
          driver = new InternetExplorerDriver(caps);
      }
  }
  
  public void masterTest(WebDriver driver, String test) {
      if (test == "test1") {
          Test1(driver);
      } else if (test == "test2") {
          Test2(driver);
      }
  }
  
  // *********************************TESTS*****************************************************
  
  public void Test1(WebDriver driver) {
      driver.get("http://www.marca.com/en/");
      driver.findElement(By.linkText("Barcelona")).click();
  }
  
  public void Test2(WebDriver driver) {
      driver.get("http://www.marca.com");
      driver.findElement(By.linkText("Fútbol")).click();
  }
  </code></pre>
  
  <p>}</p>