我们可以在从另一个功能内部调用功能时传递方法和路径吗

Can we pass method and path while calling feature from inside another feature

当你从另一个功能内部调用一个功能(有几个场景)时,我想传递方法和路径 因为这些是常见的场景 - 从两个不同的端点调用,其中基础 url 保持不变但路径和方法也不同。

出现这种情况是因为我试图将常见场景放在一个功能中,并从其他功能文件中调用该功能,这些场景都是常见的,它们仅在路径和方法上有所不同。

我已经提到了这个问题:'https://github.com/intuit/karate/issues/239' 并且知道这是可能的,但在我的情况下,我需要在调用功能文件时将路径和方法作为参数传递,因为这是与调用常用场景的两个模块

所以问题是我们可以在调用功能文件时将路径和方法作为参数传递。目前我收到错误,但不明白为什么会失败。 我尝试了以下内容: booking.feature 背景: * def pathVar = '/bookings'

 Scenario: Calling basic validation feature for create booking module
    * call read('classpath:feature/basic-validations.feature') {path1: '#(pathVar)', action: 'post'}

basic-validations.特征

背景: * url 基本网址 * header 接受 = 'application/json' * def 数据 = 读取(数据文件) * header API-Version = 1 * 路径 '#(path1)' * header授权='Bearer'+data.booking.token

   Scenario: Empty request validation
          Given request {}
          When method '#(action)'
          Then status 400

    Scenario: Request-Body element is empty or null.
          Given def req = ({ "request_body": null })
          And request req
          When method '#(action)'
          Then status 400

   Scenario: When parameter value for name in request body is incorrect.
          Given def req = ({ "request_body": [ { "name": "shipment_standard_booking", "action": 
          "create", "path": "/standardBooking", "body": data.booking.standardBooking.requestBody }] 
           })
          And def name = 'test'
          And set req.request_body[*].name = name
          And request req
          When method '#(action)'
          Then status 400
          And match $.debugMessage == 'Validations failed due to bad input payload request. WorkItem 
          name (' +name+ ') is invalid'

path步骤可以带变量。 method 步骤也可以带一个变量: https://github.com/intuit/karate#method

* def methodVar = 'post'

* url foo
* request bar
* method methodVar

但我完全不推荐它 - 或您正在采用的方法。原因在这里解释一下,请花点时间阅读:

我想你也对嵌入表达式有误解,所以请阅读:https://github.com/intuit/karate#rules-for-embedded-expressions

如果您仍然决定这样做并卡住了,您可以假设空手道不支持您想要做的事情 - 或者您需要贡献代码。

另请阅读此文以获得其他想法: