Ask a Question

Call external javascript function from Groovy in SoapUI

Azar
New Contributor

Call external javascript function from Groovy in SoapUI

Hi, 

 

We have a requirement where we have to call an external javascript function within groovy script in SoapUI, This was possible from Java using :

ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript")
engine.eval(new FileReader(JAVA_SCRIPT_FILE_PATH))
Invocable invocable = (Invocable) engine
String result = invocable.invokeFunction(JAVA_SCRIPT_MAIN_METHOD, <Method Parameter List>)

 

However, same java code is not working in groovy and definitely itseems like something is missing here, Reaching out for any sort of help this community can provide here

 

Thanks in advance

6 REPLIES 6
nmrao
Champion Level 2

And the error is?



Regards,
Rao.
Azar
New Contributor

It keeps saying 'cannot invoke method eval() on null object'

 

PFA

 

soapUI_Error.JPG

Azar
New Contributor

Hi Team,

 

Any update on this query, Much appreciate if anyone could share their inputs

 

Regards,

Azar

nmrao
Champion Level 2

Are you sure that the script is correct?

It appears that below engine is null.

engine = new ScriptEngineManager().getEngineByName("javascript")

 



Regards,
Rao.
nmrao
Champion Level 2

May you can look at the following source for better ideas

https://github.com/SmartBear/soapui/blob/9f6817b6d0552a6f3dd7e62ac6c28c459214b9fe/soapui/src/main/ja...



Regards,
Rao.
williamsmith262
New Contributor

Calling external JavaScript functions within Groovy scripts in SoapUI can be achieved by ensuring compatibility between Groovy and the JavaScript engine. Just as seamless integration is vital in coding, a smooth coordination between technology and healthcare services like "Servicio de Enfermeria a Domicilio" ensures optimal patient care. Collaboration and compatibility are key.

cancel
Showing results for 
Search instead for 
Did you mean: