【发布时间】:2018-01-23 08:46:34
【问题描述】:
我正在使用两种不同的环境进行测试 - Dev env 没有身份验证(因此我们不必传递标头),而 QA env 托管在 API Gateway 上。我试图设计我的测试,以便测试应该可配置为在任一环境中运行。
这是我所做的:
在 Karate-config.js 中定义客户端密码和客户端 ID。为 dev 设置这两个变量为 null。
-
调用用户登录场景文件生成授权令牌(从场景文件中获取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