How can I take a generated token from a Test Suite and add it as an Authorization header?

520 Views Asked by At

I'm having an issue with a readyAPI project i'm migrating. I'm not a backend-lover so it's quite diff from my perspective, hope you guys have another pov and can give me a hand.

Here's the issue: From the first TestSuite I got a Bearer token which I use to authenticate in each next service. Problem is that I do not know how to take this token from the first test without setting it manually into the next service's properties. I mean, I want the token to be setted automatically without the need of setting it manually.

Here's how I got the token

I've this groovy script but I do not know how it exactly works (I didn't created it)

So I think that by variables I can get the token from the first test but I'm not really sure on how to adapt it. I think that I need to add to this variable the "Bearer " words to make it work, but I cannot see the how to.

Sorry if im not being clear, I'll be glad to add any further information if you guys can help me :)

Thank you very much in advance.

2

There are 2 best solutions below

0
On

Well I added a "Bearer " + to the Groovy script that was implemented and then an Authorized test step to the next tests and it worked! :) If anyone need more info about this workaround I'll be glad to share it.

0
On

what kind of authentication are you using? Are you just retrieving a jwt back from an endpoint?

Depending on the answer, you might be able to create an auth profile to retrieve the token and use it as part of your request test step. It would save you having to manually add the "Bearer :" part to your token. Might not be a fit, and if not can maybe look at other options https://support.smartbear.com/readyapi/docs/requests/auth/types/index.html