Rayrun
← Back to Discord Forum

How can a bearer token returned in a setup project be used in extraHTTPHeaders?

I am testing an API in isolation; we don't have a web front end for this product.

I have a request that hits Auth0 and returns a JSON payload with an access_token property. storageState does not persist that bearer token from the response to disk, it looks like it only logs cookies from the response, unless I am not understanding that.

I can use fs to write my own file and read it back in for requests later.

Or I can use await context.setExtraHTTPHeaders({ 'Authorization': Bearer ${token} }) in my setup project, and then pull them back out and populate the request with this header manually.

Is there way to automatically pipe the access_token into extraHTTPHeaders that I missed in the docs? Thanks.

This thread is trying to answer question "Is there a way to automatically pipe the `access_token` into `extraHTTPHeaders` in the setup project?"

2 replies

I can do this with a file, and I can hijack the cookie with context.addCookies, but this approach looks cleanest (if it worked):

In my setup project I am doing await context.setExtraHTTPHeaders({ 'Authorization': ``Bearer ${token}`` }) but that does not pass on to the context in the test from what I can tell. I am reading about contexts and it is saying there is a merge that happens, but that also new contexts are created for tests, and am not sure if modifying extra headers on a context should propagate to the tests.

hey @rschooley , did you ever solve this?

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].