我们使用GWT提供的SimplePager来提供数据集的记录/页面导航。我们想要测试我们是否正确地控制了Next/Previous按钮的启用状态。虽然按钮允许我们为按钮指定启用/禁用的图像,但“SimplePager”本身是ImageButton的一个内部类,它扩展了Image而不是按钮。因此,生成的HTML不使用Button enabled/disabled属性,而是为每个状态提供不同的嵌入图像。
有没有什么合理的方法来检测Selenium中启用了SimplePager导航按钮的状态?
发布于 2013-02-12 22:59:48
在标准实践中,您应该创建自定义组件,比如Image按钮。我建议您使用ISFW,它提供了可以与注释一起使用的creating custom component特性。在component中,您可以根据AUT指定中的行为。
发布于 2013-04-01 20:06:31
重写代码示例以获得更好的格式。
public class ImageButton extends Component{
public ImageButtom (String loc){
super(locator);
}
@Override
public boolean isEnabled() {
//custom representation!...
return this.getAttribute("class").contains("imgdisabled");
//return this.getCssValue("background").contains("imgdisabled");
//return this.getAttribute("src").contains("imgdisabled");
}
}您可以在测试页面中使用此组件,如Webelement
@FindBy(locator="locator")
ImageButton prevButton;
@FindBy(locator="locator")
ImageButton nextButton;在测试代码中
page.prevButton.verifyEnabled();
page.prevButton.assertEnabled();发布于 2014-11-13 18:29:07
查看SimplePager的源代码,它看起来像是使用生成器来创建css样式,其中禁用状态(和启用状态)有一个应用于它的css类(我将使用这个https://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/cellview/client/SimplePager.java?r=9614)。
因此,如果您能够以某种方式访问实际的Resources客户端包,那么您可以调用resources.simplePagerStyle().disabledButton()来获取一个字符串,该字符串是禁用按钮的CSS类,然后可以将其用作selenium中的定位器。这可能真的很棘手,因为运行selenium测试的jvm可能无法引用已编译的GWT代码(即,当您调试GWT应用程序时运行的代码)。
或者,您可以子类化SimplePager,而不是使用DEFAULT_RESOURCES客户端包,传入您自己的类名,然后您可以控制用于禁用按钮的类名(通过创建您自己的Style类,它只包装从原始客户端包获得的现有类,但在返回值中添加前缀或其他东西)。
它有点乱,因为组件是完全封装的,而您试图了解它的内部。
https://stackoverflow.com/questions/14469593
复制相似问题