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

时间:2018-02-19 15:21:02

标签: karate

我对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

这是user-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中的任何指针。

提前致谢!

1 个答案:

答案 0 :(得分:3)

最简单的方法是通过命令行将它们作为Java系统属性传递,您可以通过测试或CI触发的运行轻松完成这些操作。

请参阅此处的文档: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'

在命令行上:

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