Need a way to set global headers(this headers are returned by feature file) for all api requests [closed]

Need a way to set global headers(this headers are returned by feature file) for all api requests [closed]



We need to pass cxrf token, cookie returned from login feature file to all the API requests.
For now, I am passing these cxrf token and cookie for each request by passing parameters to calling feature files.



Is there any way to set these values globally.



enter image description here



Calling feature:


@userManagement
Feature: Access Profile creation, updating, and deletion Test



Background:


* 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



Need a way to make cxrf token and cookie headers as global for all called features



This question appears to be off-topic. The users who voted to close gave this specific reason:






Never post pictures of text when you can post the actual text. Be sure that it is properly formatted and readable.

– user177800
Sep 17 '18 at 15:44






I have updated the code sample for your reference. Please have a look

– Anupama
Sep 17 '18 at 15:54




1 Answer
1



Refer this example: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/headers/call-updates-config.feature



Especially this part:


Background:
* callonce read('common.feature')



Now the variables in common.feature will be global. This will solve your problem.


common.feature



Please please please read the documentation here: https://github.com/intuit/karate#shared-scope






Hi Peter, This solution works perfectly fine. But I am facing issue to configure heades in js file. my headers are returned from common.feature. I need to put them in js file and call that js file in called feature. my headers include X-CSRF-TOKEN,JSESSIONID. how to set values for heades in js file so that it can be used for called feature. waiting for response. Thanks in advance

– Anupama
Sep 18 '18 at 1:50







@Anupama please. i know reading docs is hard for you, but please try harder. i am busy today

– Peter Thomas
Sep 18 '18 at 1:52

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

PHP code is not being executed, instead code shows on the page

Ĝň ċũ,İĨĻĐđēĵſ ĤŹĝĽķũ ĆŹđě,ļ łĂģĚ ŻŷĶĸĦķĖĝŔ ūŬĿŜćīŴĽĺ,ľ,ũĽňĎźāœ,ĉŃĩ,ĎĻē,ŕųūČœijčĶŶĻijŕ,ĩěŗſŗāŸņŰž,Žů ĭğŪľ Čŗćļžĵţ Ūĉņ ĵ ůŁ ţŅ,ĮŶ ŁŵĮ śŁĬŇŏ ŮĜʼnœĦā,Ũŏ Ź ŖŀšĦ ŃłĉŹŅťŸŇ,ŷī