title: TestNG Using @Factory and @DataProvider
body: <p>I'm very new using TestNG and Java programming in general and I have a question in regards to using @Factory and @DataProvider together.</p>
  
  <p>I want to test submitting a web form multiple times with different input data every time.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>public class SolicitudEmpleo extends LaunchBrowser { 
  
  private String campoDni;
  private String firstName;
  private String lastName;
  
  @Factory (dataProvider="dataProviderMethod")
  public SolicitudEmpleo(String campoDni, String firstName, String lastName){
      this.campoDni=campoDni;
      this.firstName = firstName;
      this.lastName = lastName;
  }
  
  @DataProvider
  public static Object[][] dataProviderMethod() {
  return new Object[][] { {"000007", "Bill", "Gates"}, {"000008", "Stack", "Overflow"} };
  
  }
  </code></pre>
  
  <p>When I run my test cases, the data provider will always use the last values contained in the array. For example, if I run the test now it will input the values: "000008", "Stack", "Overflow" into the web form and completely ignore "000007", "Bill", "Gates".</p>
  
  <p>Thanks!!</p>
  
  <p>EDIT: I printed all three Strings in the function:</p>
  
  <pre><code>@Factory (dataProvider="dataProviderMethod")
      public SolicitudEmpleo(String campoDni, String firstName, String lastName){
          this.campoDni=campoDni;
          this.firstName = firstName;
          this.lastName = lastName;
  
          System.out.println(campoDni);
          System.out.println(firstName);
          System.out.println(lastName);
      }
  </code></pre>
  
  <p>Console:</p>
  
  <p>000007
  Bill
  Gates
  000008
  Stack
  Overflow</p>
  
  <p>EDIT 2: I'll post the entire code with the test cases so you guys can take a look and see if you can spot the mistake:</p>
  
  <pre><code> public class SolicitudEmpleo extends LaunchBrowser { 
  
      private String campoDni;
      private String firstName;
      private String lastName;
  
      @Factory (dataProvider="dataProviderMethod")
      public SolicitudEmpleo(String campoDni, String firstName, String lastName){
          this.campoDni=campoDni;
          this.firstName = firstName;
          this.lastName = lastName;
  
          System.out.println(campoDni);
          System.out.println(firstName);
          System.out.println(lastName);
      }
  
      @DataProvider
      public static Object[][] dataProviderMethod() {
      return new Object[][] { {"000007", "Bill", "Gates"}, {"000008", "Stack", "Overflow"} };
  
      }
  
  
  @Test (priority = 1)
  public void testCase1() throws InterruptedException {
  
      Thread.sleep(3000);
      WebElement addButton = driver.findElement(By.xpath("//*[@id='pt1:r1:0:b3_2']/a/span"));
      addButton.click();
  
  }
  
  @Test (priority = 2)
  public void testCase2() throws InterruptedException { 
  
      Thread.sleep(5000);
      Select dropdown = new Select (driver.findElement(By.id("pt1:r1:1:s2:soc1A::content")));
      dropdown.selectByVisibleText("Dropdown");
  
      Thread.sleep(5000);
      WebElement campoDNI = driver.findElement(By.xpath("//*[@id='pt1:r1:1:s2:it1::content']"));
      campoDNI.sendKeys(campoDni);
  
      WebElement verifyButton = driver.findElement(By.xpath("//*[@id='pt1:r1:1:s2:b1']/span"));
      verifyButton.click();
      Thread.sleep(5000);
  
  }
  
  @Test (priority = 3)
  public void testCase3() throws InterruptedException {
  
      WebElement firstNameElement = driver.findElement(By.xpath("//*[@id='pt1:r1:2:it2::content']"));
      firstNameElement.sendKeys(firstName);
  
      WebElement lastNameElement = driver.findElement(By.xpath("//*[@id='pt1:r1:2:it3::content']"));
      lastNameElement.sendKeys(lastName);
  
  }
  
  @Test (priority = 4)
  public void testCase4() throws InterruptedException {
  
      Thread.sleep(2000);
      WebElement saveFormButton = driver.findElement(By.xpath("//*[@id='pt1:r1:2:b12']/a/span"));
      saveFormButton.click();
      Thread.sleep(6000);
  
  }   
    }
  </code></pre>
  
  <hr>
  
  <pre><code>public class LaunchBrowser {
  
  WebDriver driver;
  
  @BeforeSuite()
  public void launchBrowser() throws InterruptedException {
      System.setProperty("webdriver.chrome.driver", "/Users/user/Documents/selenium-2.40.0/chromedriver");
      driver = new ChromeDriver();
      driver.get("http://webform.jsf");
      driver.findElement(By.id("pt1:pt_s1:itUsuario::content")).sendKeys("username");
      driver.findElement(By.id("pt1:pt_s1:itClave::content")).sendKeys("password");
      driver.findElement(By.id("pt1:pt_s1:itClave::content")).sendKeys(Keys.ENTER);
      Thread.sleep(5000);
  }
  
   }
  </code></pre>
  
  <p>Also, the XML file for this test:</p>
  
  <p><code>&lt;suite name="Parameter test Suite" verbose="2"&gt;
          &lt;test name="Parameter Test one"&gt;
            &lt;classes&gt;
            &lt;class name="test.classes.SolicitudEmpleo"&gt;
            &lt;/class&gt;
           &lt;/classes&gt;
         &lt;/test&gt;
     &lt;/suite&gt;</code></p>