I have an issue that I am facing, I want to create a function that waits until the text "Other" exists in List. I want it to wait 30 seconds, and in every 5 seconds it will do the call again and validate the new list. (Maximum 5 - 6 times to validate if the text exists in the new list ). I have done the validation by converting the List into map and check any match (the map converting and the checking is working).
The problem is with the wait mechanism, I try to create complex fluent wait that will also receive boolean in case of finding the expected text and then the wait should stop. But I do not figure out what to return if it is not found the text for example in the first or second tries, and I want it to still wait and made the call again and validate again.
I want the wait to stop only in two cases:
- the word "Other" exists - in this case isExists is true.
- the the time passes is more than 30 seconds.with pulling interval of 5 seconds and the word "other" not displayed
Is there a way to set in the condition of the wait to wait for Boolean == true ?I am not sure that the condition Boolean>() is correct and can be done here in the wait.until , and if it will work
public void testrIntegrationfluent ()
{
WebElement element = BasePage.getWebElementByXPathWithWaitToClicable("//nz-select[@formcontrolname='selectedIntegrationTypes']/div");
element.click();
WebDriver driver2 = WebDriverMgr.getDriver();
Wait wait = new FluentWait(driver2)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
wait.until(new Function<WebDriver , Boolean>() {
public Boolean apply (WebDriver driver2) {
List<WebElement> dropdownOptions = driver2.findElements(By.xpath("//ul[contains(@class, 'ant-select-dropdown-menu')]/li"));
Boolean isExists = dropdownOptions.stream().map(WebElement::getText).anyMatch(text -> "Other".equals(text));
if (isExists.equals(true)) {
return isExists;
}
return ****** need to think what to put thatkeep waiting and perform call for list and validation reoccured ******
}
});
}