Perform following steps,
- In playwright.cofig.ts, create a project
- Provide test name:
- Provide testDir:
- In use:
- Provide baseURL:
- Provide extraHTTPHeaders:
- 'Accept':
- 'Content-Type':
- In test, call back request instead of page
- In request.METHOD('URL')
- request.get('URL')
- request.post('URL', {body})
- Get the response in a variable
- const response = request.get('/products')
- For status, response.status()
- For header, response.headers()
- For body, response.body()
- For JSON, response.json()
- Also others availble
- For assertions, use expect
- For status, expect(response.status()).toBe(200)
- For header content type match
- expect(response.headers()['conten-type']).toContain('application/json')
- Get the response body in a variable
- const responseBody = response.json()
- For assertions in the body
- expect(responseBody).toHaveProperty('success', true)
- expect(responseBody).toHaveProperty('data')
- expect(Array.isArray(responseBody.data)).toBe(true)
- Run test project-wise, run with the following command
- npx playwright test --project project_name_given_playwright.config
No comments:
Post a Comment