RCPTT running Java code from the script

家住魔仙堡 提交于 2020-01-14 09:08:49

问题


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?


回答1:


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...



来源:https://stackoverflow.com/questions/39488040/rcptt-running-java-code-from-the-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!