Karate 空手道API测试-将变量从一个功能文件传递到另一个功能文件
我希望将授权头作为变量传递给另一个功能文件。下面是我正在尝试做的一个示例:Karate 空手道API测试-将变量从一个功能文件传递到另一个功能文件,karate,Karate,我希望将授权头作为变量传递给另一个功能文件。下面是我正在尝试做的一个示例: Feature: Resource Creation Background: * url baseUrl Scenario: Create Resource Given def basictoken = 'Basic Zn*****' And def token = call read('classpath:
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
当at和头授权=“#(basictoken)”
有办法让我通过吗?当我将其硬编码为其值时,我看不到任何问题。您能帮助我们如何将变量从一个特征文件传递到另一个特征文件吗。提前感谢。请进行以下更改:
Given def token = call read('classpath:endpoints/UserLogin.feature') { basictoken: 'Basic Zn*****' }
还请注意,对于作用域中存在的简单变量(也继承自“调用”功能),您不需要#(foo)
约定:
And header Authorization = basictoken
我不明白为什么最初的代码不起作用。“basictoken”有一个外部定义,所以调用的文件中不应该有这个定义吗?@davidfrancis从文档中,我认为我们需要将基本令牌传递给调用的功能,即UserLogin.feature,它将被使用。除非我们将令牌传递给UserLogin,否则登录名将不知道功能文件。如果您发布完整的示例,我相信Peter会帮您查看。我们不再使用空手道。