描述:升级到空手道 1.1.0.RC3 后收到参考错误消息
脚步:
执行test.feature文件
测试特征
Scenario: Get custom request
* def testUtils = call read('classpath:features/utils.feature')
* def getRequest = testUtils.customRequest()
* print getRequest
实用程序.feature
Feature: common utilities
Scenario:
* def randomAlphabetic = function (count) { return org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(count) }
* def customRequest =
"""
function() {
var name = randomAlphabetic(2)
return {
name:name,
city:'Bangalore'
}
}
"""
错误信息 :
org.graalvm.polyglot.PolyglotException: ReferenceError: "randomAlphabetic" is not defined
- <js>.:anonymous(Unnamed:2)
Git 存储库供参考 -https://github.com/naveenkrao/karate-sample-project https://github.com/naveenkrao/karate-sample-project
新版本中 JS 函数的重用存在一些限制。有多种解决方法。下面是在 JS 块本身内移动可重用函数的示例:
* def customRequest =
"""
function() {
var randomAlphabetic = function (count) { return java.lang.System.currentTimeMillis() + '' };
var name = randomAlphabetic(2);
return {
name:name,
city:'Bangalore'
}
}
"""
或者如果你做了randomAlphabetic
全局可用的函数,例如通过karate-config.js
它也可能有效。
这是我们努力解决的 JS 引擎更改的结果。如果这对您来说是个问题,我们非常欢迎您贡献代码。我们认为不是,有很多方法可以创建可重用的函数,遵循一些规则 - 保持简单,更喜欢 Java 来实现复杂的逻辑,并且不要过多地混合或组合 JS 或 Java。
如果您认为需要更新,也欢迎您贡献文档。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)