Need to populate multiple input fields in a registration form multiple times reading data from excel sheet

1,035 views
Skip to first unread message

Shravan Kumar

unread,
May 12, 2014, 12:54:35 PM5/12/14
to webd...@googlegroups.com
Hi,

I have a requirement where I need to populate multiple input fields in a registration form multiple times. I have prepared excel file with 4 rows and 11 columns.

The thing is each row contains single user data, that I need to populate into registration form, like that 4 users and their data to be filled. I have to automate it.
I'm using Selenium Webdriver for this requirement.

I'm enclosing excel data with the code that I'm trying.

Could you please help me with the logic of how to iterate this functionality. I have been trying for the whole day.

Thanks a lot for your cooperation,

with regards,
Shravan
excel1.png
rakesh3.png
excel2.png

Venkatesh PS

unread,
May 13, 2014, 7:33:09 AM5/13/14
to webd...@googlegroups.com
Why don't you use testng DataProvider.

Ashish Srivastava

unread,
May 13, 2014, 7:54:23 AM5/13/14
to webd...@googlegroups.com
If you are not too specific about excel sheets, I would suggest don’t use them as it’s not a scalable option. Try using TestNG DataProvider mechanism instead, it will save you from writing code for looping through the input data which TestNG does on it’s own. The other option you could try, which I have tried successfully in past is using enums for organising input data, you still would write code for looping but this is a scalable option. Using DataProvider will always prove better in terms of scalability and cleanliness of code and reporting.

with regards,
Ashish
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.
<excel1.png><rakesh3.png><excel2.png>

Seenu Vasu

unread,
May 13, 2014, 8:54:09 AM5/13/14
to webd...@googlegroups.com
Use dataprovider...it is very good option for you..

Thanks
Sreenivas

darrell

unread,
May 15, 2014, 12:09:18 AM5/15/14
to webd...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages