首页 > 解决方案 > 如何将单个参数传递给单独的功能文件

问题描述

我在下面尝试将参数发送到单独的功能文件(通过遵循此示例),但是它没有按预期工作。

项目特征

   * def id = '55000000005021'
   * def result = call read('delete_project.feature')

delete_project.feature

 Given path 'project', '#(id)'
 When method DELETE
 Then status 200
 Then match response.status == 'success' 

低于异常

com.intuit.karate.exception.KarateException:projects.feature:48 - delete_project.feature:11 - 状态代码为:404,预期:200,响应时间:239,url:https://localhost:8080/project/% 23(id) 响应:{"status":"failure","data":{"error_code":"INVALID_URL_PATTERN","message":"请检查尝试访问的 URL 是否正确"}} 在✽ .* def result = call read('delete_project.feature') (projects.feature:48)

还有一个疑问,如何通过传递 id 列表来迭代它。我在 foo 变量中有多个 id,我想为该 foo 变量中的每个可用 id 调用delete_project.feature

* def foo = get response.data[*].id

标签: karate

解决方案


我认为你过于复杂的路径参数,更改为:

Given path 'project', id

并阅读这部分文档:https ://github.com/intuit/karate#rules-for-embedded-expressions


推荐阅读