【发布时间】:2018-03-14 19:06:41
【问题描述】:
我正在准备 testFramework 并想知道将所有 Findby 对象保留在 PageClasses 中是否是个好主意,例如:
我有 PageClasses:
public class MainPage extends BaseExtendablePage implements Dataaa {
@FindBy(xpath = photo1) WebElement photo1;
@FindBy(xpath = "//p/i/a/img[@src= 'http://demoqa.com/wp-content/uploads/2014/08/pattern-14-300x237.png']") WebElement photo2;
@FindBy(xpath = "//div/i/a/img[@src= 'http://demoqa.com/wp-content/uploads/2014/08/pattern-14-300x237.png']") WebElement photo3;
...
我尝试了一些类似实现接口 Dataaa 并至少从 xpath's, id's... 中放入 String 的方法:
public interface Dataaa {
String photo1 = "//p/a/img[@src= 'http://demoqa.com/wpcontent/uploads/2014/08/pattern-14-300x237.png']";
}
这是保留这些元素或如何将它们移动到其他位置的好方法还是有更好的主意?
【问题讨论】:
-
您能否说明您的
PageClasses与PageObjects有何不同? -
我没听懂你的问题 :(
-
@DebanjanB 我认为它们应该是相同的。要回答 OP 的问题,FindBy 注释中定义的定位器必须是文字或常量,因此如果要定义字符串,则需要为
final String -
另外,
@FindBy(xpath = photo1) WebElement photo1;在任何情况下都是没有意义的,因为它是自我引用的 -
所以保持原样或将字符串移动到界面?
标签: java selenium automated-tests pageobjects findby