【问题标题】:How can i call the js function in karate feature file with 1 argument如何使用 1 个参数调用空手道功能文件中的 js 函数
【发布时间】:2020-07-05 15:19:41
【问题描述】:

在我的一个测试场景中,我发出请求,我想从对数组的响应中收集数据,为此我在karate-config.js 中定义了 js 函数,它接受一个参数。

当我调用它时,我总是遇到同样的错误,但是当我使用另一个具有静态值的函数时它工作得很好,但是当我尝试传递动态对象(来自预请求的响应)时它会失败。 这是错误:

记录器功能调用失败:classpath:integration/base_oai_pmh_tests/mod-configuration-integration-cases.feature
参数:空
mod-configuration-integration-cases.feature:14 - 为 :33 生成字节码失败

我传递给函数的对象是好的,它绝对不为空。

here is the function into config file
here is the scenrio with js function usage

我也尝试了这些可能的解决方案,但它们也失败了:

  • 后台定义js函数
  • 在场景中定义js函数

【问题讨论】:

标签: javascript java karate web-api-testing


【解决方案1】:

如果getConfigurationEntryIds是一个JS函数,那么就这样做:

* def configIds = getConfigurationEntryIds(configResponse)

【讨论】:

    【解决方案2】:

    Karate 不支持箭头函数,我们应该使用 karate.map 而不是 js map 函数,如果你想从 json 数组中收集数据,那么使用 JSON 路径会更好:def configIds = configResponse.configs[ *].id

    【讨论】:

    • 错了,应该是$configResponse.configs[*].id
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    相关资源
    最近更新 更多