Ask a Question

how to use token id in second request

SOLVED
dev16
Contributor

how to use token id in second request

i am using soapui 5.2.1 where in first login request i am getting token id and this token id i want to use in second request so how to automated this token id and this token id will expire in 24 hrs . and my request and response is in JSON

 

Thanks,

Mahadev

17 REPLIES 17
nmrao
Champion Level 3

Please see if the below thread is helpful. Provide your raw response otherwise.

https://stackoverflow.com/questions/39757652/soapui-rest-response-session-token/39761209#39761209


Regards,
Rao.

Thanks for your valuable reply

I am getting plain token id while Run the login request

after login request, next step case is create one medical info .

 

 

1) first login request----getting Token as response ( here i need to add script assertion as "def jsonString = context.response" ...correct ?)

2) in second medical info add request ..in parameter what i need to add...or where and what i need to add 

 

so please request you explain me elaborately because soapui rest api testing is new for me .. 

 

 this token id is expiring in 24 hrs so every time and every further step  i do not want to add token id so based on that plz guide me

E.g. in response

eyJdssdsddke90klfdO46j0dcJLx4t1XbE

 

Thanks,

Mahadev

nmrao
Champion Level 3

Can you please show the raw response of login step?

Yes, once the token id is fetched store it at project level (unlike storing at test case level in the above thread)

context.testCase.testSuite.project.setPropertyValut('TOKEN', <value>)

Now, you for rest of your test steps / cases/ suites, you can use it as
${#Project#TOKEN}


Regards,
Rao.

Thanks Rao Sir.

 

My Login raw step request is

{
 "username":"testuser1",
 "password":"abc"

 

and I am getting token no in json respone

E.g.dlskdsdlk4404904094fdkkflkfldtriooirt08989889988oirttr

 

1) so for project level in PROPERTY will add

Name: context.testCase.testSuite.project.setPropertyValut('TOKEN', <value>)

Value                : dlskdsdlk4404904094fdkkflkfldtriooirt08989889988oirttr

2) and in test steps / cases/ suites level ...add property

Name: ${#Project#TOKEN}

Value: dlskdsdlk4404904094fdkkflkfldtriooirt08989889988oirttr

 

please anything above wrong then correct me..

 

 

and now my second doubts is in my project 3 types user available

1) testuser

2) demouser

3) admin

So for each user login i am getting token id ..which i need to use for next test run of that user

 

so  can i follow same above 1 and 2 step for remaining 2 user also ?

 

if yes it means in project level in property level i need to set 3 token value

 

correct ? plz sugget

 

Thank you very much

 

BR

Mahadev

 

 

 

 

 

nmrao
Champion Level 3

AreN'T you supposed to get a json response? Just getting only token as response? A screen shot of raw response would help better. 

 

If you just getting only token, then script needs to changed to handle that.

 

If you have multiple users to test, then save them as : <USERNAME>_TOKEN at project level and use appropriately.

 

for example, testuser token is fetched, save it as TESTUSER_TOKEN and its value at project level and use it as ${#Project#TESTUSER_TOKEN} where needed in the rest of the project.

 

Hope this clear.

 

 



Regards,
Rao.
nmrao
Champion Level 3

Humble request, no need to call Sir.


Regards,
Rao.

Thanks

 

okay lots of my doubts are clear  its really very informative and useful .

 

i m adding some screenshots so plz guide me i am added property or not .

 

Thanks,

Mahadev

 

 

nmrao
Champion Level 3

Based on the screen shots, it appears that you have't got it quite right.

 

For the login step, add below Script Assertion and remove the existing project property that you have added.

 

 

assert context.response
//Replace the USERNAME in below
context.testCase.testSuite.project.setPropertyValue('<USERNAME>_TOKEN', context.response)

 



Regards,
Rao.

Thanks

i tried but its not work (in login request asseration added script asseration wher i have paste the given below script where replace the login user name and run the same and close the script assertion.

after that in second test case/step i run then its failed asking token id

 

can you please explain or show me with screenshots ..it will really helpful for me

 

I am very thankful if you guide me on this.

 

Thanks

Mahadev

cancel
Showing results for 
Search instead for 
Did you mean: