空手道 API 测试 - 将变量从一个特征文件传递到另一个特征文件

Karate API Testing - Passing variable from one feature file to another

我希望将授权 Header 作为变量传递给另一个功能文件。这是我正在尝试做的一个例子:

    Feature: Resource Creation
      Background:
        * url baseUrl

        Scenario: Create Resource
          Given def basictoken = 'Basic Zn*****'          
          And def token = call read('classpath:endpoints/UserLogin.feature')
          Given path 'lobs'
          And header X-XSRF-TOKEN = token.xsrftoken
          And header Cookie = 'SESSION='+token.scookie+'; '+'XSRF-TOKEN='+token.xsrftoken
          And request [{"name":"Boston"}]
          When method post
          Then status 200

这是它引用的文件:

Feature: Common User Login
Background:
  * url baseUrl

Scenario:
  Given path 'security/user'
  And header Authorization = '#(basictoken)'
  When method get
  Then status 200
  Given path 'rname/name'
  When method get
  Then status 200
  And def xsrftoken = responseCookies["XSRF-TOKEN"].value
  And def scookie = responseCookies["SESSION"].value

我在 And header Authorization = '#(basictoken)' 时遇到错误 有什么办法可以通过吗?当我将它硬编码为它的值时,我看不到任何问题。您能否帮助我们了解如何将变量从一个特征文件传递到另一个特征文件。提前致谢。

请进行此更改:

Given def token = call read('classpath:endpoints/UserLogin.feature') { basictoken: 'Basic Zn*****' }

另请注意,对于作用域中存在的简单变量(也继承自 "calling" 特性),您不需要 #(foo) 约定:

And header Authorization = basictoken