如何在空手道多部分文件中动态指定文件路径?

发布于 2025-01-25 20:36:03 字数 640 浏览 2 评论 0原文

对每个不同的环境都有几个不同的文件。

src
|
+-- java
|  |
|  +-- test.feature
|
+-- resources
|  |
|  +-- dev
|  |  |
|  |  +-- file.txt
|  |
|  +-- qa
|     |
+     +-- file.txt  

我需要将文件上传到特定的端点,但是我 并使用它来指示多部分文件步骤中的文件路径:

And multipart file file = { read: "classpath:#(environment)/file.txt", filename: 'file.txt', contentType: 'multipart/form-data' }

但是,当我尝试此操作时,空手道似乎并没有真正替换##(环境)使用适当的变量,正如我所期望的那样到:

org.graalvm.polyglot.PolyglotException: not found: #(environment)/file.txt

我还尝试使用空手道替换功能,但这也失败了。

还有其他方法可以在空手道中指定这样的文件路径吗?

I need to upload a file to a specific endpoint, but I have a couple of different files for each different environment I'm testing the endpoint in. I have a file structure similar to this:

src
|
+-- java
|  |
|  +-- test.feature
|
+-- resources
|  |
|  +-- dev
|  |  |
|  |  +-- file.txt
|  |
|  +-- qa
|     |
+     +-- file.txt  

So I thought to assign the environment to a variable and use it to indicate the file path in the multipart-file step:

And multipart file file = { read: "classpath:#(environment)/file.txt", filename: 'file.txt', contentType: 'multipart/form-data' }

However, when I tried this, Karate didn't seem to actually replace #(environment) with the proper variable, as I expected it to:

org.graalvm.polyglot.PolyglotException: not found: #(environment)/file.txt

I also tried to use the Karate replace functionality, but that failed for me as well.

Is there any other way to specify a file path like this in Karate?

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

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

发布评论

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

评论(1

吻安 2025-02-01 20:36:04

请阅读以下内容: https://github.com/karatebs/karate #karatebs/karate#rules-wrules--wrules--com- for-embedded-expressions

所以请尝试以下操作:

 * def filename = 'classpath:' + environment + '/file.txt'
 And multipart file file = { read: "#(filename)", filename: 'file.txt', contentType: 'multipart/form-data' }

Please read this: https://github.com/karatelabs/karate#rules-for-embedded-expressions

So try this:

 * def filename = 'classpath:' + environment + '/file.txt'
 And multipart file file = { read: "#(filename)", filename: 'file.txt', contentType: 'multipart/form-data' }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文