我使用硒。我有这样的页面对象:
public class Portal extends Utils{
private WebDriver driver;
private final By getReason= By.xpath("//a[contains(text(),'Get Sol')]");
public Portal(WebDriver driver) {
super(driver);
this.driver = driver;
}
public VisitReason clickCurrentReason() {
clickIn(getReason);
return new VisitReason(driver);
}
}
我想要这种方法:clickCurrentReason()返回新的Object扩展Utils类,并将其传递给参数:driver。怎么做?我知道我必须使用泛型。我找到了解决方案的一部分:
public<T extends Utils> T clickCurrentReason(){
clickIn(getReason);
return (T)(driver);
}
但是如何返回:“返回新对象(驱动程序)”
public void Test() {
TestingEnv testingEnv = new TestingEnv(driver);
Portal portal = testingEnv.openPage();
VisitReason visitReason = portal.clickCurrentReason();
//sometimes instead of the last line it will be: VisitInSpot visitInSpot = portal.clickCurrentReason();
//sometimes instead of the last line it will be: VisitBack visitBack = portal.clickCurrentReason();
}