title: Java Cucumber Using Keys From Property File In Examples Table
body: <p>Its been a long time since I have worked with Scenario Outlines. What I wanted to achieve was to reference keys from my config_data.properties file in the Examples table, so that I have once source of truth for content/data for my tests. </p>
  
  <p>I have been getting an error on the steps that need to get the data from the properties file and the value that gets entered into the first name text box when I run my test is firstName1 not the value in the properties file. The error in question:</p>
  
  <pre><code>[31morg.openqa.selenium.WebDriverException: unknown error: keys should be a 
  string
  </code></pre>
  
  <p>Here is what I have:</p>
  
  <p>Feature File:</p>
  
  <pre><code>@new_test
  Scenario Outline: User fills out the Personal Info Form With Valid Data
  And I enter a first name as "&lt;first_name&gt;"
  And I enter a middle name as "&lt;middle_name&gt;"
  And I enter a last name as "&lt;last_name&gt;"
  
  
  
  Examples:
  
  |first_name | middle_name | last_name | 
  |firstName1 | middlename1 | lastname1 |
  </code></pre>
  
  <p>Step Definitions: (I think this is where the problem is)</p>
  
  <pre><code>public class PersonalInfoFormSteps {
  
      private PersonalInfoFormPage personalInfo;
  
      private DataReader data;
  
      @When("^I enter a first name as \"([^\"]*)\"$")
      public void i_enter_a_first_name_as(String first_name) throws Throwable {
      personalInfo.getFirstNameField().click();
      data.loadData().getProperty(first_name);
      personalInfo.getFirstNameField().sendKeys(first_name);
  
      }
  }
  </code></pre>
  
  <p>DataReader.class (This works fine for getting data that does not involve scenario outline)</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Properties;
  
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.support.ui.WebDriverWait;
  
  import net.serenitybdd.core.pages.PageObject;
  
  public class DataReader extends PageObject {
  
  WebDriverWait wait = null;
  private WebDriver driver;
  
  String result = "";
  InputStream inputStream;
  File file = new File(
          "file path to properties file goes here");
  
  public DataReader(WebDriver driver) {
      super();
  }
  
  public Properties loadData() throws IOException {
      Properties prop = new Properties();
      FileInputStream fileInput = null;
      try {
          fileInput = new FileInputStream(file);
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }
  
      // load properties file
      try {
          prop.load(fileInput);
      } catch (IOException e) {
          e.printStackTrace();
      }
      return prop;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Properties File Data:</p>
  
  <pre><code>firstName1: Mickey
  middleName1: M
  lastName1: Mouse
  </code></pre>