我如何导出为全局变量
How do i export as global variable
我有一个空手道功能文件
Scenario: Feature
Given url 'https://testlocal/v1/test/authorize'
And request 'type=code&uri=http://www.testlocal/app'
And header Accept = 'application/x-www-form-urlencoded'
And header Content-Type = 'application/x-www-form-urlencoded'
When method POST
Then status 302
* def code = responseHeaders['Location'][0].substring(59,95)
* print code
当我 运行 上面的功能文件时,我可以看到单独打印的代码,但是我想在同一功能文件的下面使用该代码
Scenario: Login
Given url 'https://testlocal/v1/test/authorize/login'
And request 'username=test1@gmail.com&password=123!&requestId=**"I am not sure how to call the above code here"**
And header Accept = 'application/x-www-form-urlencoded'
And header Content-Type = 'application/x-www-form-urlencoded'
When method POST
Then status 302
谢谢
听起来您只需要一个 Background:
部分,将其作为一个很好的重用示例:headers.feature
.
如果您确实需要跨多个功能文件重复使用,请参阅有关如何 re-use feature files via the call
keyword 的文档。
我想建议改进您的测试,您可以使用 form field
语法执行以下操作而不是手动形成请求:
编辑:完整解决方案
Background:
Given url 'https://testlocal/v1/test/authorize'
And form field type = 'code'
And form field uri = 'http://www.testlocal/app'
When method post
Then status 302
And def code = responseHeaders['Location'][0].substring(59,95)
Scenario: login
Given path 'login'
And form field username = 'test1@gmail.com'
And form field password = '123!'
And form field requestId = code
When method post
Then status 302
我有一个空手道功能文件
Scenario: Feature
Given url 'https://testlocal/v1/test/authorize'
And request 'type=code&uri=http://www.testlocal/app'
And header Accept = 'application/x-www-form-urlencoded'
And header Content-Type = 'application/x-www-form-urlencoded'
When method POST
Then status 302
* def code = responseHeaders['Location'][0].substring(59,95)
* print code
当我 运行 上面的功能文件时,我可以看到单独打印的代码,但是我想在同一功能文件的下面使用该代码
Scenario: Login
Given url 'https://testlocal/v1/test/authorize/login'
And request 'username=test1@gmail.com&password=123!&requestId=**"I am not sure how to call the above code here"**
And header Accept = 'application/x-www-form-urlencoded'
And header Content-Type = 'application/x-www-form-urlencoded'
When method POST
Then status 302
谢谢
听起来您只需要一个 Background:
部分,将其作为一个很好的重用示例:headers.feature
.
如果您确实需要跨多个功能文件重复使用,请参阅有关如何 re-use feature files via the call
keyword 的文档。
我想建议改进您的测试,您可以使用 form field
语法执行以下操作而不是手动形成请求:
编辑:完整解决方案
Background:
Given url 'https://testlocal/v1/test/authorize'
And form field type = 'code'
And form field uri = 'http://www.testlocal/app'
When method post
Then status 302
And def code = responseHeaders['Location'][0].substring(59,95)
Scenario: login
Given path 'login'
And form field username = 'test1@gmail.com'
And form field password = '123!'
And form field requestId = code
When method post
Then status 302