How to pass method return value as parameter to the web UI keyword?

I’ve created a method in groovy to generate random number, My requirement is to return this random number and wants to pass a parameter to the Send Keys command(built in web UI keyword) in manual mode(input column).
How can i pass the method return value to the webUI keyword as input parameter?

@Keyword
def String getRandomNumber(int num){
Random random = new Random()
String number= "Property "+ random.nextInt(10 ** num).toString()
// return "Property "+ random.nextInt(10 ** num).toString()
return number
}

Thanks in advance!

Have you tried this

WebUI.sendKeys(findTestObject(‘yourTestobject’), getRandomNumber(5))

I’ve tried as you suggested, getting “groovy.lang.MissingMethodException: No signature of method: Script1577948762655.getRandomNumber() is applicable for argument types: (java.lang.Integer) values: [8]”.

Are you sure you haven’t changed anything in getRandomNumber() method definition? Please post more of the error message.

I haven’t changed in getRandomNumber() method:
please find the error message:

Test Cases/WebPortal/Tc_001_AddNewProperty FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: Script1577948762655.getRandomNumber() is applicable for argument types: (java.lang.Integer) values: [8]
at Tc_001_AddNewProperty.run(Tc_001_AddNewProperty:74)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1578035127335.run(TempTestCase1578035127335.groovy:23)

groovy code to generate random number:
public class GenerateRandomNumber {

@Keyword
def String getRandomNumber(int num){
	Random random = new Random()
	String number= "Property "+ random.nextInt(10 ** num).toString()
	//	return "Property "+ random.nextInt(10 ** num).toString()
	return number
}

}

Sorry, I’m unable to reproduce the behavior. It works on my machine.
The error is complaining saying the method is expecting an int value and you are giving it 8 so that’s strange.
That is why I first thought you changed something in method definition.

Hi @lokesh.kambhoji

It seems that there is a redundant asterisk (multiplication). Is this a typo or is it in your code ? Try to use just one asterisk instead.

How is the value passed to your function? Directly or through a variable?
looks like is a list with the element 8 into it, not an integer.

I was facing the same error. I tried giving the full path for the keyword ‘getRandomNumber()’ and it worked. For e.g.
WebUI.sendKeys(findTestObject(‘yourTestobject’), CustomKeywords.‘com.myPackageName.MyClassName.getRandomNumber’(5))

TIA