I've been using a page object model to find elements and perform actions on them e.g.
public class loginPage extends HelperClass
{
@FindBy(xpath = ("//button[@type='submit']"))
private WebElement loginButton;
public loginPage clickLogin()
{
loginButton.click()
return this;
}
}
From within my JUnit test I'd call the function thus:
WebDriver driver = setUpBrowser("FireFox", websiteURL);
loginPage LoginPage = new loginPage(driver);
delay(5000); //delay 5 seconds
LoginPage.clickLogin();
You will have noticed the explicit delay which is not ideal. So I decided to write a wait method like this:
public void waitForElementAndClick(WebElement element, WebDriver driver)
{
WebDriverWait wait = new WebDriverWait(driver, 30);
//wait.until(ExpectedConditions.visibilityOf(element));
wait.until(ExpectedConditions.or
(
ExpectedConditions.visibilityOf(element), ExpectedConditions.elementToBeClickable(element)
));
System.out.println(element);
element.click();
}
All works well so what is the problem you ask? Well the problem is it is a huge maintenance effort to go and change all the code I've written to accommodate this wait feature. I'll need to change the JUnit calls to include the driver e.g.
LoginPage.clickLogin(driver);
Then in the page object model I'll have to change all the methods as well e.g.
public loginPage clickLogin(WebDriver driver)
{
waitForElementAndClick(loginButton, driver);
return this;
}
Is there an easier way of doing this without having to go through all the code applying these changes?