简体   繁体   English

Karate-config.js - 是否有可能在其他地方使用 java class 的方法?

[英]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.

相关问题 将Json传递给karate-config.js文件 - Pass Json to karate-config.js file Karate-config.js 文件未在 eclipse 中保存为 JS 文件 - Karate-config.js file is not saved as JS file in eclipse 空手道 - karate.configure('headers', { Accept: 'application/json' }); 在 karate-config.js 文件中无法识别。 它说缺少导入语句 - Karate - karate.configure('headers', { Accept: 'application/json' }); is not recognized in karate-config.js file. It says missing import statements 可以在JS中使用Abstract类吗? - Possible to have Abstract class in JS? 由以下原因引起:com.intuit.karate.exception.KarateException:ReferenceError:空手道配置js文件中未定义“ XMLHttpRequest”异常 - Caused by: com.intuit.karate.exception.KarateException: ReferenceError: “XMLHttpRequest” is not defined Exception in Karate config js file 通过函数传递elementID然后返回变量并在别处使用。 可能? - Pass an elementID through a function then return variable and use elsewhere. Possible? 如何获得组件rich:modalPanel的所有可用Java脚本方法? - How is it possible to get all available java script methods of the component rich:modalPanel? 类仿真中的JS和方法 - JS and methods in class emulation 使用deployJava.js在javascript中调用java方法 - use deployJava.js to call java methods in javascript "在 Graal.js 中使用 java 类" - Use java class in Graal.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM