我有一个情况,我想为我的字段定义各种行为。
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();
}
//...
}
我有一个名为SomePage的类,它是一个页面对象(使用Page Factory模式),其中包含字段(WebElement
)。
根据字段名称的后缀,我需要创建一些方法。如果后缀是*Select
,则该字段将具有许多方法,这些方法可以适用于所有select字段
。如果后缀是*Button
,则它将具有button字段
所需的方法。
我能否根据字段名称的后缀
生成自定义方法?
注意:IntelliJ支持修改自定义Getter和Setter,但不允许每个字段有多个方法。它限制每个字段只有一个Getter和一个Setter。但实际情况并非总是如此,例如我的某些字段可能需要多个setter或getter。