我已经为登录页面编写了Page对象类来测试UI外观&感觉网络,iphone&药片,平板对于每个验证,我都编写了一个方法来返回该元素的cssValue或文本。
增加单个类中定义的lot方法的编写。有没有什么方法可以减少在页面对象类中声明的任何方法?
示例:
public String getBannerCssValue(String cssValue){
return getCssValue(driver.findElement(banner), cssValue);
}
public String getSmartPhoneLegendText(){
return getElementText(driver.findElement(smartPhoneLegend));
}
public String getSmartPhoneLegendCssValue(String cssValue){
return getCssValue(driver.findElement(smartPhoneLegend), cssValue);
}
public String getTabletLegendText(){
return getElementText(driver.findElement(tabletLegend));
}
public String getTabletLegendCssValue(String cssValue){
return getCssValue(driver.findElement(tabletLegend), cssValue);
}
public String getButtonTextValue(){
return getAttribute(driver.findElement(login), "value");
}
public String getSubmitButtonCssValue(String cssValue){
return getCssValue(driver.findElement(login), cssValue);
}
public String getForgotPasswordCssValue(String cssValue){
return getCssValue(driver.findElement(forgotYourPassword), cssValue);
}
public String getTabButtonTextValue(){
return getAttribute(driver.findElement(tabletSubmit), "value");
}
我认为您应该以实际使用这些getter的方式为指导。
在我的代码中,我经常将多个控件读入一个对象:页面上的用户数据读入一个user对象。所以我有一个单独的吸气剂。
在其他情况下,在我没有(或不需要)对象的情况下,我为单独的控件提供了单独的getter。
有一些或所有这些getter的setter吗?如果是这样,请考虑将getter/setter对合并为一个函数。我在我的博客上写过这件事:
- Getters和Setters