我具有身份验证功能,但想使其可重用。我无法通过到目前为止尝试过的方法进行工作。
有效的独立方法是:
# Created at 10/4/18
Feature: #Authentication Management
Background:
* url gatewayUrl
* def myid = 'myid'
* def mysecret = 'mysecret'
Scenario: # Generate authentication token for x user
Given path 'mypath'
And header Content-Type = 'application/x-www-form-urlencoded'
And request 'grant_type=api_key&myid=' + myid + '&mysecret=' + mysecret
When method post
Then status 200
* print response.Token
这是该请求的有效POST请求:
1 > POST <authURL>
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 108
1 > Content-Type: application/x-www-form-urlencoded; charset=UTF-8
1 > Host: <authURL>
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/10.0.2)
grant_type=api_key&myid=myId&mysecret=mySecret
我想用执行通话功能中的参数替换 myid 和 mysecret 。使用'#(myid)'和'(#mysecret)'似乎在任何地方都行不通,但在定义参数时有效。有没有办法进行这种替换,或者是建立发送请求数据的另一种等效方法?
谢谢
答案 0 :(得分:0)
当然值得仔细阅读文档:https://github.com/intuit/karate#calling-other-feature-files
尝试一下:
Feature: #Authentication Management
Scenario: # Generate authentication token for x user
Given url gatewayUrl
And path 'mypath'
And header Content-Type = 'application/x-www-form-urlencoded'
And request 'grant_type=api_key&myid=' + myid + '&mysecret=' + mysecret
When method post
Then status 200
然后调用如下:
Feature: main
Background:
* def result = call read('auth.feature') { myid: 'actualid', mysecret: 'actualsecret' }
* def token = result.response.Token
# remaining test uses token