Karate 空手道-测试不同环境-带或不带API网关

Karate 空手道-测试不同环境-带或不带API网关,karate,Karate,我使用两种不同的环境进行测试-Dev env没有身份验证(因此我们不必传递头),QA env托管在API网关上。我试图设计我的测试,使测试可以配置为在两种环境中运行 以下是我所做的: 在Karate-config.js中定义客户端机密和客户端Id。为dev将这两个变量设置为null 调用用户登录场景文件以生成授权令牌(从场景文件中获取url、客户端id和客户端机密),并将令牌返回到场景文件 特点:空手道测试 Background: * configure ssl = true

我使用两种不同的环境进行测试-Dev env没有身份验证(因此我们不必传递头),QA env托管在API网关上。我试图设计我的测试,使测试可以配置为在两种环境中运行

以下是我所做的:

  • 在Karate-config.js中定义客户端机密和客户端Id。为dev将这两个变量设置为null

  • 调用用户登录场景文件以生成授权令牌(从场景文件中获取url、客户端id和客户端机密),并将令牌返回到场景文件

    特点:空手道测试

      Background:
        * configure ssl = true
        * url baseUrl
        * def token = call read('classpath:endpoints/user-login.feature')
        * def headerData = {Authorization: #(token.nextGen),Accept: 'application/json;v=1'}
        * headers headerData
    
      Scenario: Verify that status for retreiving endpoint
        Given path 'abc'
        When method get
        Then status 200
    
    功能:获取令牌

    Scenario: Get authorization header
      Given url 'https://api-it.cloud.xyz.com/oauth2/token?client_id=12121&client_secret=12121&grant_type=client_credentials'
      When method get
      Then status 200
      And def tokenType = response.token_type
      And def accessToken = response.access_token
      * def nextGen = tokenType + ' '+ accessToken
      * print nextGen
    

  • 任何关于如何在同一项目上运行带有或不带有身份验证的测试的指针都将受到赞赏

    请查看文档的这一部分:


    请注意,
    eval
    是从0.7.0开始的,但是您可以轻松地使用JS函数,在in中设置
    if
    条件,并执行您需要的操作-从JS函数中创建
    karate.call()
    来设置标题(或不设置标题)。

    Thans@Peter Thomas,这很有帮助。