This is more of test design question than pure Selenium question. I have a form in my application and while following page object pattern I wrote a method which has many parameters -
newMerchantPage.addEditMerchant(merchantDomain, merchantName,
merchantCategory, true, merchantDescription, merchantNotes,
merchantTags, true, true, false, false, merchantTitle,
additionalDescription, merchantHeading, dummyCouponLink, true);
Method looks horrible, and then I was suggested to break it down in multiple small method in page object class i.e
typeMerchantDomain(String merchantDomain) {
//
}
typeMerchantName(String merchantName) {
//
}
and then call them instead of my heavy weight method. There is one more advantage of this approach that if I can easily do data validation only individual field.
Is it the way to go about it? I feel my code would yet be crowded as I would have to make many more method calls than just one "heavy" method call I am doing right now. Any suggestions?
n.b. I posted this question on java forum, but this should be better place to get test automation design related answers.
UPDATED CODE -
After many suggestions (using "this" set methods and passing object to method), I made modification and another method of mine looks as -
ContactPage contactPage = new ContactPage(driver);
setContactFormData()
contactPage.setName(name).setEmailAddress(emailAddress).SOME MORE SETTERS;
contactPage.submitContactForm(contactPage);
Here my page object - contactPage is used to call the method and the same object is passed to method to determine what data is to be passed on to web page fields eventually.
Is this implementation of calling method on object and passing same object as argument ugly? Should I be creating a "PageDate" sort of class having ContactData class so that I could do -
contactPage.submitContactForm(contactDataObject);