The number of parameters in the method

I have a Selenium test that fills out a form. I have a method for it, but this method is overgrown in terms of the number of parameters -

newMerchantPage.addEditMerchant(merchantDomain, merchantName, merchantCategory, true, merchantDescription, merchantNotes, merchantTags, true, true, false, false, merchantTitle, additionalDescription, merchantHeading, dummyCouponLink, true); 

There are only lines and logical. I thought to use a collection and then iterate over the collection in the called method to do some more processing. Although not sure if this is the way to go. Any recommendations?

MODIFIED METHOD:

After doing a couple of preliminary messages, my method (of another method) looks like this:

 ContactPage contactPage = new ContactPage(driver); setContactFormData(); contactPage.setName(name).setEmailAddress(emailAddress).setSubject(subject).setMโ€Œ โ€‹essage(message); contactPage.submitContactForm(contactPage); 

submitContactForm, in turn, calls various utilities. How does that look bad? Especially the last line (a method call on an object and the same object passed as an argument)?

+4
source share
4 answers

One common approach is to wrap parameters in a class. This class could then provide set methods that return this to provide a good chain. (See ProcessBuilder for a good example.)

Example:

 MerchantData data = new MerchantData(); // initialize with sensible defaults data.setDomain("example.com") .setName("Some Name") .setTags("tag1, tag2); newMerchantPage.addEditMerchant(data); 
+5
source

I assume that you are using a Selenium (or RC) server.

The suggestions for wrapping data in a Merchant class are good and make sense, especially from a pure Java point of view.

However, your main concern here at Selenium is the form you are filling out, not the sellerโ€™s domain object.

Perhaps you could break your method down into smaller methods like openMerchantForm (...) typeNameInMerchantForm (...) chooseMerchantCategory (...)

etc., depending on what type of control is installed in the form. This will reflect the behavior you are testing, rather than directly installing domain objects, etc.

Hope this helps.

+2
source

Maybe write a Merchant class, create an instance with the method value and pass the instance instead?

 newMerchantPage(Merchant merchant); 

Advantage: you can save the test parameters in files and do something like:

 Merchant merchant = new Merchant(); merchant.populate(File testdata, int record); 
+1
source

Have you considered creating a class if the parameters you specify belong to the same one, and then pass the object as a parameter.

0
source

All Articles