0

我已经为登录页面编写了 Page 对象类来测试 Web、iphone 和平板电脑的 UI 外观。对于每个验证,我都编写了一个方法来返回该元素的 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"); 
}
4

1 回答 1

-2

我认为您应该以实际使用这些吸气剂的方式为指导。

在我的代码中,我经常将多个控件读入一个对象:页面上的用户数据被读入一个用户对象。所以我有一个单一的吸气剂。

在其他情况下,我没有(或不需要)对象,我有单独的 getter 用于单独的控件。

是否有一些或所有这些吸气剂的二传手?如果是这样,请考虑将 getter/setter 对合并到一个函数中。我在我的博客上写过这个:

于 2014-04-12T18:05:06.637 回答