如何在页面对象模型中使用参数驱动程序返回通用类型的新对象

问题描述 投票:0回答:1

我使用硒。我有这样的页面对象:

    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);        
    }

但是如何返回:“返回新对象(驱动程序)”

java selenium generics reflection pageobjects
1个回答
0
投票
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();

    }
© www.soinside.com 2019 - 2024. All rights reserved.