Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97770

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

$
0
0

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)"

@Test method:

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

    }

Viewing all articles
Browse latest Browse all 97770

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>