APIRequestContext
This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test.
Each Playwright browser context has associated with it APIRequestContext instance which shares cookie storage with the browser context and can be accessed via BrowserContext.APIRequest or Page.APIRequest. It is also possible to create a new APIRequestContext instance manually by calling ApiRequest.NewContextAsync().
Cookie management
APIRequestContext returned by BrowserContext.APIRequest and Page.APIRequest shares cookie storage with the corresponding BrowserContext. Each API request will have Cookie
header populated with the values from the browser context. If the API response contains Set-Cookie
header it will automatically update BrowserContext cookies and requests made from the page will pick them up. This means that if you log in using this API, your e2e test will be logged in and vice versa.
If you want API requests to not interfere with the browser cookies you should create a new APIRequestContext by calling ApiRequest.NewContextAsync(). Such APIRequestContext
object will have its own isolated cookie storage.