空手道测试框架 - 在 github 之外存储凭据

Karate Test Framework -Storing credentials outside of github

我在 Amazon API Gateway 上有 API 的空手道测试。因此,在我的空手道测试中,我必须提供 client_idclient_secret 进行身份验证。我想知道是否有一种方法可以将凭据存储在我的 github 存储库之外并在 运行 时间使用它。在空手道中可以这样做吗?

我的测试是这样的:

Feature: API Test all endpoints using Karate

  Background:
    * configure ssl = true
    * url baseUrl
    * def res = (env == 'qa'? 'classpath:endpoints/user-login.feature' : 'classpath:endpoints/user-login-dev.feature')
    * def token = call read(res)
    * def headerData = {Authorization: #(token.nextGen),Accept: 'application/json;v=1'}
    * headers headerData

这里是用户-login.feature文件

Feature: API Test using Karate

  Background:
    * configure ssl = true

    Scenario: Get authorization header
      Given url 'https://api.cloud.xyz.com/oauth2/token?client_id=****&client_secret=****&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
      * def headerData = {Authorization: nextGen,Accept: 'application/json;v=1'}

有关如何在 运行 时将 client_idclient_secret 传递给测试而不存储在 github 中的任何指示。

提前致谢!

最简单的方法是通过 command-line 将它们作为 Java 系统属性传递,您可以很容易地通过测试或 CI 触发 [=25] =].

请参阅此处的文档:https://github.com/intuit/karate#dynamic-port-numbers

在您的情况下它可能是什么样子的示例:

Given url 'https://api.cloud.xyz.com/oauth2/token'
And param client_id = karate.properties['client.id']
And param client_secret = karate.properties['client.secret']
And param grant_type = 'client_credentials'

在 command-line 上:

mvn test -DargLine="-Dclient.id=**** -Dclient.secret=**** -Dkarate.env=qa"