Our QA Automation Test project uses Selenium with data-qa attributes. Our company is proposing having Individual Methods for each By attribute: eg for SendKeys, Clear()
I believe this may lead to duplicate coding, and can triple the code base.
Option 1:
SendKeys Method for each Attribute
private By StreetNameTextbox => By.XPath("//*[@data-qa='streetname']");
private By CityTextbox => By.XPath("//*[@data-qa='city']");
private By StateTextbox => By.XPath("//*[@data-qa='state']");
private By ZipCodeTextbox => By.XPath("//*[@data-qa='zipcode']")
public void SendKeysStreetNameTextbox(string value) => SendKeys(StreetNameTextbox, value);
public void SendKeysCityTextbox(string value) => SendKeys(CityTextbox, value);
public void SendKeysStateTextbox(string value) => SendKeys(StateTextbox, value);
public void SendKeysZipCodeTextbox(string value) => SendKeys(ZipCodeTextbox, value);
public void ClearStreetNameTextbox(string value) => FindElement(StreetNameTextbox).clear()
public void ClearCityTextbox(string value) => FindElement(CityTextbox).clear()
....
Option 2:
Don't need individual SendKeys and clear, just use native Selenium Send Keys or company wrapper function, why have repetition? Test user can just input appropriate data-qa tag id.
private By StreetNameTextbox => By.XPath("//*[@data-qa='streetname']");
private By CityTextbox => By.XPath("//*[@data-qa='city']");
private By StateTextbox => By.XPath("//*[@data-qa='state']");
private By ZipCodeTextbox => By.XPath("//*[@data-qa='zipcode']")
SendKeys(variablename, value);
clear()
The question is, do we really need repetition in Option 1? Company is saying, Page Objects should not really work with By DataTags as little as possible. Is this true? What is best practice?