Axios is not included by default in Playwright projects, so you need to install it.
Open your terminal and navigate to the root directory of your Playwright project.
Run the following command to install axios:
npm install axios
To organize API tests separately, create a dedicated folder or file for them:
Create a folder named tests/api inside your tests directory (or use an existing structure).
Example:
tests/
api/
api.test.js
e2e/
e2e.test.js
Create a new file for your API tests, e.g., api.test.js.
At the top of your api.test.js, import axios and any required Playwright modules.
const axios = require('axios');
const { test, expect } = require('@playwright/test');
Set a base URL for the API you want to test. This will make your code cleaner and reusable.
const baseUrl = '<https://your-api-url.com>'; // Replace with your API's base URL