脚本运行java,RCPTT从脚本运行Java代码

由于AUTrunner运行在独立进程中,无法直接执行任意Java代码。但可以通过invoke和invoke-static脚本命令调用AUT中的现有Java类和方法。如果需要实现特定代码,可以创建测试支持包并在AUT中声明静态方法,或者通过实现ECL命令扩展功能。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值