Skip to content

mwaz/api-testing-with-playwright

Repository files navigation

Playwright Test API

CircleCI

This project is a simple API server built with Node.js and Express. It is designed to be a testing backend for the "API testing with Playwright" tutorial for CircleCI.

It provides basic endpoints for fetching users, creating users, and simulating a user login.

Prerequisites

  • Node.js (v16 or later)

  • npm (usually comes with Node.js)

Installation

Clone the repository or save the index.js and package.json files to a new directory.

git clone [email protected]:mwaz/api-testing-with-playwright.git

Navigate to the project directory in your terminal.

cd api-testing-with-playwright

Install the required dependencies by running:

npm install

Running the Server To start the API server, run the following command from the project's root directory:

npm start

You should see a confirmation message in your terminal: Test API server is running on http://localhost:3000

Info: The API server is also hosted on Vercel at https://api-testing-with-playwright-b1gd.vercel.app, which makes it easier to run the tests on CI.

Available API Endpoints: The server provides the following endpoints:

Authentication

POST /api/login

  • Simulates a user login.

  • Request Body: { "username": "any_username", "password": "any_password" }

  • Success Response (200): Sets an authToken cookie and returns { "message": "Login successful" }.

  • Error Response (401): { "message": "Invalid credentials" }.

Users GET api/users

  • Fetches a list of all users.

  • Success Response (200): Returns an array of user objects.

[
  { "id": 1, "name": "Alice", "email": "[email protected]" },
  { "id": 2, "name": "Bob", "email": "[email protected]" }
]

POST api/users

Creates a new user.

  • Request Body: { "name": "John Doe", "email": "[email protected]" }

  • Success Response (201): Returns the newly created user object.

  • { "id": 3, "name": "John Doe", "email": "[email protected]" }

  • Error Response (400): { "message": "Name and email are required." }.

Details

This repo is built following a tutorial published on CircleCI blog under the CircleCI Guest Writer Program.

About CircleCI Guest Writer Program

Join a team of freelance writers and write about your favorite technology topics for the CircleCI blog. Read more about the program here.

Releases

No releases published

Packages

No packages published