简体   繁体   中英

RCPTT running Java code from the script

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 (ie, 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. Eg, 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM