I am building a selenium automation framework wherein I have a BasePage class which contains common methods used by all the web pages such as:
verifyTitle and verifyElement. For both the methods, I have used expectedconditions class i.e
ExpectedConditions.titleIs(eTitle) and wait.until(ExpectedConditions.visibilityOf(element).
Code as below:
public void verifyElement(WebElement element){
WebDriverWait wait = new WebDriverWait(driver, 10);
try{
wait.until(ExpectedConditions.visibilityOf(element));
Reporter.log("Element is present ", true);
}
catch(Exception e){
Reporter.log("Element is not present ", true);
Assert.fail();
}
}
public void verifyTitle(String eTitle){
WebDriverWait wait = new WebDriverWait(driver, 10);
try{
wait.until(ExpectedConditions.titleIs(eTitle));
Reporter.log("Page is displayed with title : "+eTitle, true);
}
catch(Exception e){
Reporter.log("Page is not displayed with title : "+eTitle, true);
Assert.fail();
}
I have built a POM class for every webpage which extends basePage class In POM class we use encapsulation.
In my test class, I will have to call the method verifyElement of BasePage class and pass the webelement which is initialized in my POM class. How can I do this? Since the webelements in POM class are private, I cannot call them in test class. But, since I have already inspected the element using @findBy
I want to reuse the XPath