简体   繁体   English

SoapUI中的Javascript

[英]Javascript in SoapUI

Javascript in SoapUI How to's? SoapUI中的Javascript如何?

In SoapUI, you are allowed to write Groovy Scripts ! 在SoapUI中,您可以编写Groovy脚本! but since even javascript is also supported in SoapUI how can we write a javascript in SoapUI Is there a simple example which would explain this in much detail.Is there any simple code for automating the process of testing using javascript. 但是,即使在SoapUI中也支持javascript,我们如何在SoapUI中编写一个javascript是否有一个简单的例子可以解释这个详细的内容。是否有任何简单的代码可以自动化使用javascript进行测试。

To switch a project to JavaScript, click on the project, travel to the window in the bottom left hand corner. 要将项目切换到JavaScript,请单击项目,然后转到左下角的窗口。 Select the script language field and update it to JavaScript. 选择脚本语言字段并将其更新为JavaScript。

As far as what you can do with it, you can really do anything. 至于你能用它做什么,你真的可以做任何事情。 You can create a script step or assertion. 您可以创建脚本步骤或断言。 Some examples would include creating a script to create variables or looping through a response to verify information. 一些示例包括创建脚本以创建变量或循环响应以验证信息。 I didn't find much on using JavaScript with soapUI either, and ended up sticking with Groovy. 我也没有找到使用带有soapUI的JavaScript,并最终坚持使用Groovy。 I found it to be powerful and extendable via Java if needed. 如果需要,我发现它是强大的,可以通过Java扩展。

If you want a specific example on how to do something. 如果你想要一个关于如何做某事的具体例子。 I'd recommend asking a more specific question with what you have tried so far. 我建议您询问一个更具体的问题到目前为止您尝试过的内容。

So far I've got... 到目前为止我已经......

function myFunction() {
log.info('Hello');
}
myFunction();

Output shows up in script log, when I work out how to loop tests etc, will post… 输出显示在脚本日志中,当我计算出如何循环测试等时,会发布...

I've not tried JavaScript, but I have developed my own java classes which I use for complex response checks. 我没有尝试过JavaScript,但是我开发了自己的java类,用于复杂的响应检查。

You don't have to change the scripting language in SoapUI. 您不必在SoapUI中更改脚本语言。 To call Java class, I have a groovy step in my test, which instantiates an object from my java class and I then invoke a key method on the object. 要调用Java类,我在测试中有一个常规步骤,它从我的java类中实例化一个对象,然后我在对象上调用一个键方法。 You can pass in the objects that SoapUI passes into the groovy script so you can then process the response. 您可以将SoapUI传递的对象传入groovy脚本,以便您可以处理响应。

The java scripts themselves live in the bin/scripts folder under SoapUI. java脚本本身位于SoapUI下的bin / scripts文件夹中。

When working on a java class, I use an external editor like Brackets. 在处理java类时,我使用像Brackets这样的外部编辑器。 When I save the change, SoapUI detects that change and recompiles the java class, so yup don't need to restart SoapUI after every tweak to your class. 当我保存更改时,SoapUI检测到更改并重新编译java类,因此在每次调整到您的类之后,不需要重新启动SoapUI。

The smart bear site and other places have tutorials to get you up and running. 智能熊网站和其他地方都有教程,可以帮助您启动和运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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