需要一种方法来为所有 api 请求设置全局 headers(此 headers 由功能文件返回)
Need a way to set global headers(this headers are returned by feature file) for all api requests
我们需要将 cxrf 令牌,从登录特征文件返回的 cookie 传递给所有 API 请求。
现在,我通过将参数传递给调用功能文件来为每个请求传递这些 cxrf 令牌和 cookie。
有没有办法全局设置这些值。
调用功能:
@userManagement
Feature: Access Profile creation, updating, and deletion Test
背景:
* def result = callonce read('classpath:ic/common/resources/LoginFinalSub.feature')
* def csrfToken = result.response.csrfToken
* def jsessionid = result.responseCookies.JSESSIONID.value
* def appServer = result.requestUri
* def routevalue = result.responseCookies.route.value
Scenario: create User
Given url appServer
* print 'create user'
* def result = call read('classpath:ic/common/UsersManagement/createUser.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid,route: routevalue, inputFile: 'ic/common/UsersManagement/createUser.json'}
Then match result.responseStatus contains 201
Then match result.response.integration.message.code contains 0
Then match result.response.integration.message.description contains 'Success'
Scenario: update user details and assert updated user details
Given url appServer
#fetch user
* def result = call read('classpath:ic/common/UsersManagement/getUserID.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userToDelete: 'testuser'}
Then match result.responseStatus contains 200
* def uid = result.user_id
* print uid
# update user details
* def result = call read('classpath:ic/common/UsersManagement/updateUser.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userId: uid, inputFile: 'ic/common/UsersManagement/updateUserInput.json'}
Then match result.responseStatus contains 200
Then match result.response.integration.message.code contains 0
#validate updated user details
* def result = call read('classpath:ic/common/UsersManagement/getUserDetails.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userId: uid}
Then match result.responseStatus contains 200
Then match result.response.integration.message.code contains 0
Then match result.response.integration.serviceData.user.id contains uid
Then match result.response.integration.serviceData.user.first_name contains 'testFirstUpdated'
Then match result.response.integration.serviceData.user.last_name contains 'testLastUpdated'
Then match result.response.integration.serviceData.user.title contains 'testUpdated'
Then match result.response.integration.serviceData.user.employee_number contains 'testUpdated'
Then match result.response.integration.serviceData.user.email contains 'testUpdated@test.com'
Then match result.response.integration.serviceData.user.username contains 'testuserUpdated'
Then match result.response.integration.serviceData.user.username contains 'testuserUpdated'
Then match result.response.integration.serviceData.user.federation_id contains 'Updated'
Then match result.response.integration.serviceData.user.accessProfileId.displayValue contains 'Regular User'
Scenario: fetch User and delete the user
Given url appServer
* def result = call read('classpath:ic/common/UsersManagement/getUserID.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userToDelete: 'testuserUpdated'}
Then match result.responseStatus contains 200
* def uid = result.user_id
* def result = call read('classpath:ic/common/UsersManagement/deleteUser.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userId: uid}
Then match result.responseStatus contains 200
Then match result.response.integration.message.code contains 0
Then match result.response.integration.message.description contains 'Success
Called features examples:
Feature: create Access Profile
Background:
Scenario: create Access Profile
Given url appServer
And path '/integration/rest/user'
And header Accept = 'application/json'
And header Content-Type = 'application/json'
And header X-CSRF-TOKEN = csrfToken
* cookie JSESSIONID = jsessionid
* cookie route = routevalue
* def inputjson = read('classpath:'+inputFile)
* print inputjson
Given request inputjson
When method post
需要一种方法使 cxrf 令牌和 cookie headers 成为所有调用功能的全局
特别是这部分:
Background:
* callonce read('common.feature')
现在 common.feature
中的变量将是全局的。这将解决您的问题。
我们需要将 cxrf 令牌,从登录特征文件返回的 cookie 传递给所有 API 请求。 现在,我通过将参数传递给调用功能文件来为每个请求传递这些 cxrf 令牌和 cookie。
有没有办法全局设置这些值。
调用功能:
@userManagement
Feature: Access Profile creation, updating, and deletion Test
背景:
* def result = callonce read('classpath:ic/common/resources/LoginFinalSub.feature')
* def csrfToken = result.response.csrfToken
* def jsessionid = result.responseCookies.JSESSIONID.value
* def appServer = result.requestUri
* def routevalue = result.responseCookies.route.value
Scenario: create User
Given url appServer
* print 'create user'
* def result = call read('classpath:ic/common/UsersManagement/createUser.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid,route: routevalue, inputFile: 'ic/common/UsersManagement/createUser.json'}
Then match result.responseStatus contains 201
Then match result.response.integration.message.code contains 0
Then match result.response.integration.message.description contains 'Success'
Scenario: update user details and assert updated user details
Given url appServer
#fetch user
* def result = call read('classpath:ic/common/UsersManagement/getUserID.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userToDelete: 'testuser'}
Then match result.responseStatus contains 200
* def uid = result.user_id
* print uid
# update user details
* def result = call read('classpath:ic/common/UsersManagement/updateUser.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userId: uid, inputFile: 'ic/common/UsersManagement/updateUserInput.json'}
Then match result.responseStatus contains 200
Then match result.response.integration.message.code contains 0
#validate updated user details
* def result = call read('classpath:ic/common/UsersManagement/getUserDetails.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userId: uid}
Then match result.responseStatus contains 200
Then match result.response.integration.message.code contains 0
Then match result.response.integration.serviceData.user.id contains uid
Then match result.response.integration.serviceData.user.first_name contains 'testFirstUpdated'
Then match result.response.integration.serviceData.user.last_name contains 'testLastUpdated'
Then match result.response.integration.serviceData.user.title contains 'testUpdated'
Then match result.response.integration.serviceData.user.employee_number contains 'testUpdated'
Then match result.response.integration.serviceData.user.email contains 'testUpdated@test.com'
Then match result.response.integration.serviceData.user.username contains 'testuserUpdated'
Then match result.response.integration.serviceData.user.username contains 'testuserUpdated'
Then match result.response.integration.serviceData.user.federation_id contains 'Updated'
Then match result.response.integration.serviceData.user.accessProfileId.displayValue contains 'Regular User'
Scenario: fetch User and delete the user
Given url appServer
* def result = call read('classpath:ic/common/UsersManagement/getUserID.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userToDelete: 'testuserUpdated'}
Then match result.responseStatus contains 200
* def uid = result.user_id
* def result = call read('classpath:ic/common/UsersManagement/deleteUser.feature') { X-CSRF-TOKEN: csrfToken, JSESSIONID: jsessionid, route: routevalue, userId: uid}
Then match result.responseStatus contains 200
Then match result.response.integration.message.code contains 0
Then match result.response.integration.message.description contains 'Success
Called features examples:
Feature: create Access Profile
Background:
Scenario: create Access Profile
Given url appServer
And path '/integration/rest/user'
And header Accept = 'application/json'
And header Content-Type = 'application/json'
And header X-CSRF-TOKEN = csrfToken
* cookie JSESSIONID = jsessionid
* cookie route = routevalue
* def inputjson = read('classpath:'+inputFile)
* print inputjson
Given request inputjson
When method post
需要一种方法使 cxrf 令牌和 cookie headers 成为所有调用功能的全局
特别是这部分:
Background:
* callonce read('common.feature')
现在 common.feature
中的变量将是全局的。这将解决您的问题。