I am looking for some way to run some Java code directly from the test script I am writing for our RCP application.
I need to set up a multi-cast socket in the test before clicking a particular button in the application. Something like this:
MulticastSocket socket = new MulticastSocket();
socket.setNetworkInterface(interfaceTarget);
InetAddress group = InetAddress.getByName("220.2.2.2");
socket.joinGroup(group);
I was unable to find any way to do this just wondering if this is possible?
You cannot execute arbitrary Java Code directly (i.e., by writing or referring to Java code in your script), because the AUT runs in a separate process and you only can communicate from the outside.
In other words, the script executes in your RCPTT IDE or test runner process. The actual application under test (AUT) just includes the RCPTT runtime which effectively opens a telnet socket by which it receives commands and sends results via a textual language. Therefore, everything must stick to that protocol and you cannot do anything not specified by the protocol out of the box.
That said, you can call existing Java classes and methods in your AUT via the invoke
and invoke-static
script commands.
Precondition for invoke
is that you are able to retrieve an object reference via the scripting language.
E.g., you can use
<get-something-from-somewhere> | get-object | invoke methodName arg0 arg1 ...
Precondition to call a static method via invoke-static
is that the method you want to call is accessible from within the AUT. To achieve this (and if your desired method is not part of the AUT already), you can add a test support bundle into your AUT which declares the static method. This way you could implement the code snippet given in your question.
Finally, as the third and most advanced option, you can add your own ECL commands. This is done by implementing an extension point defined by the AUT runtime and including the implementation as bundle in your AUT (similar to the invoke-static
approach, but much more flexible, because you can build command chains.
For all three cases, this link serves as a starting point to executing any kind of custom code in the AUT...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With