空手道框架的一个JS文件中可以有多个JS函数吗? [英] Is it possible to have multiple JS functions inside one JS file of karate framework?

查看:77
本文介绍了空手道框架的一个JS文件中可以有多个JS函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对JSON响应的结果执行两项操作.那么我们可以在单个JS文件中进行那些不同的操作吗?还是我们需要像一个JS文件那样进行一次操作的映射. 请为此提供帮助

I need to perform two operations on the result of JSON responses.so can we have those different operations inside single JS file? or do we need to have mapping like one JS file for one operation. Please help on this

推荐答案

我不建议尝试在Karate中创建复杂的JavaScript,这只会导致可维护性问题.如果您确实希望对象具有多个实用程序方法,请编写带有静态方法的Java类,这样将更易于维护/调试.

I don't recommend trying to create complicated JavaScript in Karate, it just leads to maintainability issues. If you really want an object with multiple utility methods on it, write a Java class with static methods, and it will be much easier to maintain / debug.

也就是说,如果您真的坚持-查看以下答案: https://stackoverflow.com/a/47002604/143475

That said, if you really insist - look at this answer: https://stackoverflow.com/a/47002604/143475

但这是我对大多数项目的建议.在一个通用"功能文件中,定义多种方法,如下所示:

But this is what I recommend for most projects. In one "common" feature file, define multiple methods like this:

* def now = function(){ return java.lang.System.currentTimeMillis() }
* def uuid = function(){ return java.util.UUID.randomUUID() + '' }

您现在可以像这样调用此功能:

You can now call this feature like this:

* call read('common.feature')

现在该功能中的所有功能都可以使用:

And now all the functions in that feature are available for use:

* def time = now()
* def id = uuid()

这篇关于空手道框架的一个JS文件中可以有多个JS函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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