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?"
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.
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].