1. Install Axios in Your Playwright Project

Axios is not included by default in Playwright projects, so you need to install it.

  1. Open your terminal and navigate to the root directory of your Playwright project.

  2. Run the following command to install axios:

    npm install axios
    
    

2. Update Your Project Structure (Optional)

To organize API tests separately, create a dedicated folder or file for them:


3. Add an API Test File

Create a new file for your API tests, e.g., api.test.js.


4. Import Required Libraries

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');


5. Define the Base URL

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