我创建了一个单独的功能文件来获取访问令牌,并将其存储在变量中。然后,我尝试在Background中使用callonce功能来获取存储的变量值,以在包含访问令牌的方案和方案大纲的功能文件中重用。但是无论如何,它总是在响应中返回null。
token.feature看起来像
Given url microsoft
And path '/f35555555555/oauth2/v2.0/token'
And header Content-Type = 'application/x-www-form-urlencoded'
And form field client_id = appClientId
And form field client_secret = appClientSecret
And form field grant_type = 'client_credentials'
And form field scope = appScope
When method post
Then status 200
And def appAccessToken = response.access_token.value
opt.feature文件看起来像这样:
Feature: GET-order
Background:
* def result = callonce read('OTP/authentication.feature')
* def token = result.appAccessToken
Scenario:
Given url fire
And path '/api/fire/v' + version + '/sms/otp'
And header Content-Type = 'application/json'
And header Authorization = 'Bearer ' + token