I have a situation where I want to define a variety of behavior for my fields.
class SomePage { //... @FindBy(id = "selectEthinicity") private WebElement ethinicitySelect; @FindBy(id = "someId") private WebElement usernameInputField; @FindBy(id = "buttonSubmit") private WebElement submitButton; public void selectEthnicity(String param) throws Exception { new Select(ethnicitySelect).selectByVisibleText(param); } public void selectEthnicityByIndex(String param) throws Exception { new Select(ethnicitySelect).selectByIndex(Integer.parseInt(param)); } public int getSelectEthinicityNumberOfOptions() { new Select(ethnicitySelect).getOptions().size(); } public void waitForOptionOfSelectEthnicityToLoad() { //logic to wait for an options of Ethinicity to load } public void selectEthnicity_Wait(String param) throws Exception { //wait //select Ethinicity } public void selectEthnicityByIndex_Wait(String param) throws Exception { //wait and //Select Ethnicity by einde } //custom method for input Field public String getUsernameInputFieldValue() { usernameInputField.getAttribute("value"); } public void enterUsernameInputField(String param) { usernameInputField.sendKeys(param); } //custom method for button public void clickSubmitButton() throws PageValidationException { submitButton.click(); } //... }
Here I have a SomePage class, which is a page object (using the Factory Pattern page), which consists of fields ( WebElement ).
Based on the field name suffix, I need to create a number of methods. If the suffix is *Select , the field will have a number of methods that may be similar for all select field . If the suffix is *Button , it will have the method that is needed for the button field .
Is it possible to create a custom method based on suffix of field names .
NOTE. IntelliJ Supports modification of custom Getters and Setters, but does not allow the use of multiple methods for each field. It limits 1 getter and 1 setter per field. For example, this is not always the case. I have multiple setter (setter type) or getter for a field.
source share