vendredi 22 novembre 2019

How to return new object of Generic Type with parameter driver in Page Object Model

I use Selenium. I have Page Object like this:

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

I would like this method: clickCurrentReason() return new Object extend Utils class and passed it parameter: driver. How to do it? I know I have to use generics. I found part of solution:

public<T extends Utils> T clickCurrentReason(){
        clickIn(getReason);
        return (T)(driver);        
    }

But how passed in return: "return new Object(driver)"





Aucun commentaire:

Enregistrer un commentaire