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

时间秒杀一切 提交于 2020-01-02 18:05:40

问题


I am looking to pass Authorization Header as a variable to another feature file. 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 ? 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.


回答1:


Please make this change:

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

All the best :P



来源:https://stackoverflow.com/questions/45824884/karate-api-testing-passing-variable-from-one-feature-file-to-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!