[英]Karate-config.js - is it possible to have methods of a java class made available for use elsewhere?
To save me having to repeat a line of code (example a) in lots of different files - wherever I want to make use of a Java method, is it possible to move that line of code to the Karate-config.js so that I can make use of the methods attached to it?为了让我不必在许多不同的文件中重复一行代码(示例 a) - 无论我想使用 Java 方法,是否可以将该行代码移动到 Karate-config.js 以便我可以利用附带的方法吗? like in (example b)?
像(示例b)中一样?
example a (line in feature file that I want to move to karate-config):示例 a(我要移动到 karate-config 的功能文件中的行):
* def LdapUtils = Java.type('com.package.something.LdapUtils')
example b (in feature file):示例 b(在功能文件中):
* def newUser = LdapUtils.addNewUser()
* def userId = newUser.uid
Yes this is possible.是的,这是可能的。 You can find examples in our test-suites, for example this one: https://github.com/karatelabs/karate/tree/v1.2.1.RC1/karate-core/src/test/java/com/intuit/karate/core/parajava
您可以在我们的测试套件中找到示例,例如这个: https://github.com/karatelabs/karate/tree/v1.2.1.RC1/karate-core/src/test/java/com/intuit/karate /核心/parajava
Personally, I discourage too much of this, we've had problems with Java interop + JS, but the good news is it is mostly resolved.就个人而言,我不鼓励这种做法,我们在 Java 互操作 + JS 方面遇到了问题,但好消息是它已基本解决。 If you go down this path, please use 1.3.0.RC1 or RC2: https://github.com/karatelabs/karate/wiki/1.3.0-Upgrade-Guide
如果你 go 走这条路,请使用 1.3.0.RC1 或 RC2: https://github.com/karatelabs/karate/wiki/1.3.0-Upgrade-Guide
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.