【问题标题】:Karate - Testing different environments - with or without API Gateway空手道 - 测试不同的环境 - 有或没有 API 网关
【发布时间】:2018-01-23 08:46:34
【问题描述】:

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

这是我所做的:

  1. 在 Karate-config.js 中定义客户端密码和客户端 ID。为 dev 设置这两个变量为 null。

  2. 调用用户登录场景文件生成授权令牌(从场景文件中获取url、client_id和client_secret)并将令牌返回给场景文件。

    功能:使用空手道进行测试

      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
    

任何关于如何在同一个项目上运行带有和不带有身份验证的测试的指针将不胜感激。

【问题讨论】:

    标签: karate


    【解决方案1】:

    请看文档的这一部分:https://github.com/intuit/karate#conditional-logic

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

    【讨论】:

    • 感谢@Peter Thomas,这很有帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-03-20
    • 2022-01-03
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多