This thread is trying to answer question "How to pass an API key value pair as the Authorization of an API call?"
This might work for you https://playwright.dev/docs/api/class-testoptions#test-options-extra-http-headers
I have used this in my project configuration, but if you are creating a new request context you will need to pass the same logic in on the constructor.
Sample config code
use: {
extraHTTPHeaders: {
'my-secret': ${process.env.MY_SECRET}
}
},
Sample new context:
const context: APIRequestContext = await request.newContext({
extraHTTPHeaders: {
'my-secret': ${process.env.MY_SECRET}
}
});
If this is not your issue and you are looking to just add additional key value pairs to you header I can give you some code sample, but I am assuming you want to add some kind of token to all your API headers.
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].