Perform following steps,
- Import {APIRequestContext} from '@playwright/test'
- Declare a variable to get the API context
- let apiContext: APIRequestContext;
- User before all to initialize the API context
test.beforeAll (async ({ playwright } )=> {
apiContext = await playwright.request.newContext({
baseURL: 'api.base.URL',
extraHTTPHeaders: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
})
})
- Destroy the context after all
test.afterAll ( async ({ }) => {
await apiContext.dispose();
})
- Make request in test as required
- await apiContext.post('URL', {data: payLoad})
No comments:
Post a Comment