2
votes

I am trying to perform an explicit wait in Katalon (which uses Groovy). I have the following code :

// wait on page change to "Dashboard"
    WebDriverWait dashboardChangeWait = new WebDriverWait(driver, 3)
    /* This is causing the following Exception : 
     *   - GroovyCastException : Attempt to cast 'true' with class 'java.lang.Boolean' to class
     *      'org.openqa.selenium.WebElement'
     * */
    WebElement element = dashboardChangeWait.until(
        ExpectedConditions.textToBe(By.cssSelector('.breadcrumb-item.active'), "DASHBOARD"))

which is giving me a GroovyCastException. I know that WebDriverWait.until takes a Function (yay, JavaScript-like coding!) argument, and that ExpectedConditions.textToBe returns a ExpectedCondition<Boolean> and until's signature is V org.openqa.selenium.support.ui.FluentWait.until(Function<Object, Object<V>> arg0) . Is there a way to perform this type of wait in Katalon, that avoids this issue?

1
/* Katalon's WebUI contains all kinds of wait methods, but none that wait for an element to contain a certain text. */ - Mike Warren

1 Answers

2
votes

You were pretty close. The ExpectedConditions method textToBe() is defined as follows:

public static ExpectedCondition<java.lang.Boolean> textToBe(By locator, java.lang.String value)

An expectation for checking WebElement with given locator has specific text

Parameters:
locator - used to find the element
value - used as expected text

Returns:
Boolean true when element has text value equal to @value

So you just need to change the return type to boolean instead of WebElement as follows:

Boolean status = dashboardChangeWait.until(ExpectedConditions.textToBe(By.cssSelector('.breadcrumb-item.active'), "DASHBOARD"))