Can a Custom Keyword return 2 or more values? Pls advice on the syntax

MultipleReturnCustomKeyword.png

I think Java / Groovy can return only one object. You could return a single array of the two strings. The calling script would store that in an array variable, then you could get the variable[0] and variable[1] as the two separate things (in the calling script).

2 Likes

Thanks for the advice. I will try that out!

Just rephrasing David’s idea as code:

CustomKeyword:

package mypackage
import com.kms.katalon.core.annotation.Keyword

class ApplicationName {
    /**
     * @return List of String: ['foo', 'bar']
     */
    @Keyword
    def List<String> getValues() {
        List<String> names = ['foo', 'bar']
        return names
    }
}

Test Case:

List<String> names = CustomKeywords."mypackage.ApplicationName.getValues"()WebUI.verifyEqual(names[0], 'foo')WebUI.verifyEqual(names[1], 'bar')
2 Likes

def fi()
{return [2,3]

}

def (a,b)= fi()

println (a)
println (b)