Lets assume that I have a list of web elements:
private List<WebElement> listOf250Movies;
To action/process the list I need to implement explicit wait.
In accordence to single responsibility principle should I create a method to deal with the wait explicitly:
public void waitForVisibilityOfElement() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.visibilityOfAllElements(listOf250Movies));
}
OR
Is it acceptable to implement the WebDriverWait into a method that aim to achive the end result – e.g. straming the output into a console?
public void printToConsole() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.visibilityOfAllElements(listOf250Movies));
for (WebElement movie : listOf250Movies) {
System.out.println(movie.getText());
}
}
Should we decouple waits from the actions or treat them as an inherent part of the process/behaviour?
Side note:
I assume, the wait method might be further decoupled by creating Utilieties class for common actions:
public void waitForVisibilityOfElement(WebDriver driver, WebElement webElement) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.visibilityOfAllElements(webElement));
}
Source: Read More