问题
Scenario 1:
url: path1
Method : POST
Headers
Accept
Content-Type
Form fields:
Username
Password
url: path2
Method:get
Headers
Accept
Content-Type
Output of path2 is CSRF TOKEN
and cookies having JESSION ID
Scenario2:
For calling any path in scenario 2 we need to pass the path2 outputs which is CXRF TOKEN
and JSESSIONID
Problem:
For our test cases we need to always pass the jsession id(this jession id should be taken from the path2 only) and csrf token from path2 to all the subsequent calls. Which is not happening now
1>Csrf token is not getting passed to scenario2
2>JESSION ID created here is different from the jesession id from path2
Wants to know if there is way to pass this csrf token and jesession id headers to different scenario please?
回答1:
First read the doc and then look at these particular examples: call-updates-config.feature and common.feature
Here's what I would do:
- try to get everything working as a SINGLE scenario first before proceeding further. normally you never need to set cookies manually
- write a re-usable feature that makes the calls to
path1
andpath2
and keep that incommon.feature
. - at the end of
common.feature
set the values of the CSRF token and JSESSIONID to variables - now you can write a second feature or scenario that calls
common.feature
. again, please read the docs, there are so many examples on how to call one feature from another and pass variables - as I said, you normally don't need to do anything to cookies, but you should be able to set the cookie like this (refer syntax for
cookie
):* cookie JSESSIONID = yourVariableName
- similarly use the
header
keyword or whichever is appropriate for setting the CSRF token correctly
来源:https://stackoverflow.com/questions/49850424/csrf-token-and-cookies-having-jession-id-are-not-passed-to-different-scenario-in