You are attempting to achieve multiple things. Break it down into parts. I would write the following:
- Create a class which holds all the information necessary to fill in a form, e.g.
class Form {
private String firstName;
private String lastName;
private String userName;
private String password;
private String confirmPassword;
private String birthMonth;
private String birthDay;
private String birthYear;
private String gender;
private String mobilePhone;
private String currentEmail;
private boolean skipVerification = false;
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
// create getters/setters for the other fields
}
Then in the test you would have:
public void fillFormTest() {
Form form = readRecord();
populateForm(form);
}
private Form readRecord() {
Form f = new Form();
// code to read the next row from the excel spreadsheet into f
return f;
}
private populateForm(Form f) {
// code to get the fields from the Form f, find the input on the website, send the field value to the form
// for example
String firstName = f.getFirstName();
driver.findElement(...).sendKeys(firstName);
// do this for all the other fields as well
}
Once you can do this once then you change the test to be a loop. For example row in the spreadsheet, read the row, populateForm(form). As others have stated, you can use features like DataProvider from TestNG but this is really just syntactic sugar.