简体   繁体   English

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

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

I am looking to pass Authorization Header as a variable to another feature file.我希望将 Authorization Header 作为变量传递给另一个功能文件。 Here is an example I am trying to do:这是我正在尝试做的一个例子:

    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

Here is the file it is referring to:这是它所指的文件:

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

I am getting error when at And header Authorization = '#(basictoken)' Is there a way I can pass it ?And header Authorization = '#(basictoken)'时出现错误,有没有办法通过它? When I hardcode it to its value, I don't see any issue.当我将其硬编码为其值时,我没有看到任何问题。 Could you help us on how to pass variable from one feature file to another.您能否帮助我们了解如何将变量从一个特征文件传递到另一个特征文件。 Thanks in advance.提前致谢。

Please make this change:请进行以下更改:

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

Also note that for simple variables that exist in scope (that are also inherited from "calling" features), you don't need the #(foo) convention:另请注意,对于存在于作用域中的简单变量(也从“调用”功能继承),您不需要#(foo)约定:

And header Authorization = basictoken  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用空手道 API 测试将变量从一个特征文件调用到另一个特征文件 - How can I call a variable from one feature file to another feature file using Karate API Testing 空手道:将变量从一个特征文件传递到另一个作为查询参数 - Karate : Passing variable from one feature file to another as a query parameter 空手道 Api 测试 - 如何将数据从一个特征文件传递到另一个特征文件 - Karate Api Testing - How to pass data from one feature file to another 在空手道中将变量从一个特征文件传递到另一个特征文件作为请求 URL(不是查询参数)的一部分 - Passing a variable from one feature file into another as a part of request URL(not query parameter) in Karate 空手道 API 测试 - 如何在同一功能中使用从 API 1 到另一个 API 的变量(响应输出) - Karate API Testing - How to use a variable (output from response) from API 1 to another API in same feature 空手道将 csv 详细信息传递到另一个功能文件 - Karate passing csv details to another feature file 在空手道中 - 从另一个特征文件调用的特征文件以及变量值 - In Karate - Feature file calling from another feature file along with variable value 如何传递 karate.prevRequest 和 response 是 arguments 从一个功能文件到另一个功能文件 - How to pass karate.prevRequest and response are the arguments from one feature file to another feature file 空手道 api 测试 - 如何从命令行读取标签名称到功能文件 - karate api testing - How to read tag names from command line to feature file 空手道 API 测试 - 在同一功能文件中的不同场景中重用变量 - Karate API Testing - Reusing variables in different scenarios in the same feature file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM