CSRF TOKEN and cookies having JESSION ID are not passed to different scenario in the karate

ぐ巨炮叔叔 提交于 2020-06-28 08:32:48

问题


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 and path2 and keep that in common.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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!