RCPTT从脚本运行Java代码 [英] RCPTT running Java code from the script

查看:67
本文介绍了RCPTT从脚本运行Java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找某种直接从为RCP应用程序编写的测试脚本中运行Java代码的方法。

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?

推荐答案

您不能直接执行任意Java代码(即,通过在脚本中编写或引用Java代码),因为AUT在单独的位置运行

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.

换句话说,该脚本在您的RCPTT IDE或测试运行器进程中执行。实际的被测应用程序(AUT)仅包括RCPTT运行时,该运行时有效地打开了一个telnet套接字,通过它它可以接收命令并通过文本语言发送结果。因此,所有内容都必须遵守该协议,并且您不能开箱即用地执行该协议未指定的任何操作。

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.

也就是说,您可以在中调用现有的Java类和方法。通过 invoke invoke-static 脚本命令访问您的AUT。

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

通过调用静态方法的前提-static 是要从AUT内部访问要调用的方法。要实现此目的(如果所需的方法还不是AUT的一部分),则可以将测试支持包添加到声明静态方法的AUT中。这样,您可以实现问题中给出的代码段。

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.

最后,作为第三个也是最高级的选项,您可以添加自己的ECL命令。这是通过实现由AUT运行时定义的扩展点并将其作为捆绑包含在您的AUT中来实现的(类似于 invoke-static 方法,但更加灵活,因为

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.

对于所有三种情况,此链接作为在AUT中执行任何类型的自定义代码的起点...

For all three cases, this link serves as a starting point to executing any kind of custom code in the AUT...

这篇关于RCPTT从脚本运行Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆