使用 Karate.mapWithKey 形成的 JSON 数组数据源时遇到“org.graalvm.polyglot.PolyglotException:ReferenceError”

发布于 2025-01-10 06:32:21 字数 743 浏览 0 评论 0原文

我正在尝试传递 JSON 数组数据源来为我的 API 测试形成动态路径。 我正在同一功能文件中使用 karate.mapWithKey 将现有数组(从另一个 API 和 JS 函数返回)转换为 JSON 数组。

当我打印 input 的值时,我确实看到了格式正确的对象列表,如下所示。

[
  {
    "keyUUID": "1234"
  },
  {
    "keyUUID": "5678"
  }
]

但是,当我运行整个功能时,我看到一个错误,如 org.graalvm.polyglot。 PolyglotException:ReferenceError:“输入”未定义

Feature: Data-Driven Feature


Scenario Outline: looping over list of json objects
  * def keys = ['1234','5678']
  * def input = karate.mapWithKey(keys,'keyUUID')
  * print input
  * When path is <name>
   Examples:
    | input |

我在这里遗漏了什么吗? 我尝试读取 json 文件,它工作正常,但使用 mapWithKey 创建的对象的 json 数组总是给出错误。

I am trying to pass a JSON Array Data Source to form a dynamic path for my API tests.
I am converting an existing Array (which I get back from another APIand JS function) to a JSON Array using karate.mapWithKey in the same feature file.

When I print the value of input, I do see a properly formatted list of objects as below

[
  {
    "keyUUID": "1234"
  },
  {
    "keyUUID": "5678"
  }
]

However, when I run the whole feature, I am seeing an error as org.graalvm.polyglot.PolyglotException: ReferenceError: "input" is not defined

Feature: Data-Driven Feature


Scenario Outline: looping over list of json objects
  * def keys = ['1234','5678']
  * def input = karate.mapWithKey(keys,'keyUUID')
  * print input
  * When path is <name>
   Examples:
    | input |

Am I missing something here?
I tried reading through a json file , which works fine but the json array of objects created using mapWithKey always gives an error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜访吸血鬼 2025-01-17 06:32:21

input [json 对象创建数组] 从 scenariooutline 移动到 Background 后,我能够解决该问题

Feature: Data-Driven Feature

Background:
  * def keys = ['1234','5678']
  * def input = karate.mapWithKey(keys,'keyUUID')
  * print input

Scenario Outline: looping over list of json objects
  * When path is <name>
   Examples:
    | input |

我收到的参考错误之前的输入现已解决。

I was able to resolve it after moving the input [json array of objects creation] from within scenario outline to Background

Feature: Data-Driven Feature

Background:
  * def keys = ['1234','5678']
  * def input = karate.mapWithKey(keys,'keyUUID')
  * print input

Scenario Outline: looping over list of json objects
  * When path is <name>
   Examples:
    | input |

The reference error I was receiving earlier for input is resolved now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文