You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This framework automates the testing of a bookstore's **RESTful API**.
4
-
A completely custom REST API has been developed using **Express.js**, referencing the structure for API endpoints from the demo testing service [FakeRestApi.Web V1](https://fakerestapi.azurewebsites.net/) which operates in static mode.
8
+
# API Automation Demo Project: REST Assured & Express.js (Node.js)
9
+
10
+
This framework automates the testing of a bookstore's **RESTful API**. A completely custom REST API has been developed using **Express.js**, referencing the structure for API endpoints from the demo testing service [FakeRestApi.Web V1](https://fakerestapi.azurewebsites.net/) which operates in static mode.
5
11
This project aims to create a maintainable test framework, implement reusable code, handle various scenarios, generate informative test reports, and establish a CI/CD pipeline for continuous integration.
6
12
7
-
Below are the tools and technologies used in this framework:<br/>
8
-
-**Programming Language**: Java
13
+
This API test automation framework utilizes TestNG and REST Assured, managed with Maven for building, and generates clear, insightful reports using Allure Report.
14
+
It provides a set of predefined test cases to ensure bookstore API functions behave as expected.
15
+
16
+
17
+
### ⚙️ Tech Stack
18
+
-**Programming Languages**: Java, JavaScript
9
19
-**Testing Framework**: TestNG
10
20
-**API Testing Library**: REST Assured
11
21
-**Reporting**: Allure Report
12
22
-**Build Tool**: Maven
13
23
-**CI/CD**: GitHub Actions
14
24
-**Backend API**: Express.js (Node.js)
15
25
26
+
### ✅ Requirements
27
+
Requires **Java 22**, **Maven 3.9.x**, and **Allure Report 2.33.x** to be installed and properly configured on your local machine.<br/>
28
+
16
29
## Table of Contents
17
-
1.[Setup local machine](#one)
18
-
*[Setting up REST API using Express.js](#two)
19
-
2.[Framework Overview](#three)
20
-
3.[Framework Structure](#four)
21
-
4.[Creating API Test Scenarios](#five)
22
-
5.[API Test Execution](#six)
23
-
6.[Generate Allure REST Assured Report](#seven)
24
-
7.[CI/CD Pipeline with GitHub Actions](#eight)
30
+
1.[Setting up REST API using Express.js](#one)
31
+
2.[Framework Structure](#two)
32
+
3.[Creating API Test Scenarios](#three)
33
+
4.[API Test Execution](#four)
34
+
5.[Generate Allure REST Assured Report](#five)
35
+
6.[CI/CD Pipeline with GitHub Actions](#six)
25
36
26
37
<aid="one"></a>
27
-
## 1. Setup local machine
28
-
#### This guide assumes the following:
29
-
* Have **Maven** and **Java 22** installed.<br/>
30
-
31
-
<aid="two"></a>
32
-
### Setting up REST API using Express.js
38
+
## 1. Setting up REST API using Express.js
33
39
The REST API, built with **Express.js**, is already set up and configured for immediate use.
34
40
The following steps provide details for understanding the setup process and exploring the existing configuration:<br/>
35
41
36
-
_**Step 1.** Project Initialization:_<br/>
42
+
### Step 1. Project Initialization:
37
43
A new project directory (`api-bookstore/`) was created, and `npm init -y` command was used to initialize the project.
38
44
This generates a `package.json` file, which is essential for managing project dependencies.
39
45
40
-
_**Step 2.** Installing Dependencies:_<br/>
46
+
### Step 2. Installing Dependencies:
41
47
The following dependencies were installed by running `npm install express body-parser nodemon`:
42
48
*`express` - the Express.js framework for building the API.
43
49
*`body-parser` - middleware for parsing request bodies, allowing easy access to data sent in POST and PUT requests.
44
50
*`nodemon` - utility that automatically restarts the server upon file changes, enhancing the development experience.
45
51
46
-
_**Step 3.** Creating `server.js`_<br/>
52
+
### Step 3. Creating `server.js`:
47
53
The core logic of the API resides in the `server.js` file. It handles routing, request processing, and data management, performing the following key tasks:
48
54
* Loads necessary libraries like Express.js for routing and request handling, and middleware for parsing incoming data.
49
55
* Creates an instance of the Express application, which serves as the foundation for the API.
@@ -54,7 +60,7 @@ The core logic of the API resides in the `server.js` file. It handles routing, r
54
60
55
61
You can explore the `server.js` file in the `api-bookstore/` directory for more details on the API implementation.
56
62
57
-
_**Step 4.** Configuring `package.json`_<br/>
63
+
### Step 4. Configuring `package.json`:
58
64
The `package.json` is an important file in Node.js projects. It has several critical functions:
59
65
* Contains **metadata** about the project, such as name, version, description, author, license, etc.
60
66
* Indicates **dependencies** which other packages (libraries) your project depends on. The `npm` uses this information to install the necessary packages.
@@ -65,18 +71,14 @@ You can explore the `package.json` file in the `api-bookstore/` directory for mo
65
71
It is used to define dependencies (**express**, **body-parser**, **nodemon**) and scripts (`start`, `dev`).
66
72
This helps to quickly set up the project by simply running `npm install`.
67
73
68
-
_**Step 5.** Run server_<br/>
74
+
### Step 5. Run server:
69
75
To start the server in development mode, use the following command `npm run dev`.
70
76
This command leverages `nodemon` to automatically restart the server whenever file changes are detected.
71
77
Upon successful startup, you should see a message similar to _"Server is running on port 3000"_ in your terminal, confirming that the API is active and listening for requests.
72
78
73
-
<aid="three"></a>
74
-
## 2. Framework Overview
75
-
This API test automation framework utilizes TestNG and REST Assured, managed with Maven for building, and generates clear, insightful reports using Allure Report.
76
-
It provides a set of predefined test cases to ensure bookstore API functions behave as expected.
77
79
78
-
<aid="four"></a>
79
-
## 3. Framework Structure
80
+
<aid="two"></a>
81
+
## 2. Framework Structure
80
82
The framework's architecture is built on a structured directory organization to ensure scalability and maintainability:<br/>
81
83
```
82
84
|--online-bookstoore-frmk/
@@ -106,8 +108,9 @@ The framework's architecture is built on a structured directory organization to
106
108
3. The `pom.xml` file in the root directory contains project information and configuration details for **Maven**, used to manage dependencies and build the project.
107
109
4. The `testng.xml` file is a configuration file used by the **TestNG** testing framework to organize and define the test suite.
108
110
109
-
<aid="five"></a>
110
-
## 4. Creating API Test Scenarios
111
+
112
+
<aid="three"></a>
113
+
## 3. Creating API Test Scenarios
111
114
Creating API test scenarios involves defining test data and expected API behavior.<br/>
112
115
113
116
**Steps to Build API Test Scenarios:**
@@ -116,8 +119,9 @@ Creating API test scenarios involves defining test data and expected API behavio
116
119
3._Define Response Specifications:_ create expected response specifications using REST Assured to validate API responses.
117
120
4._Execute API Requests:_ perform API requests using the generated test data and validate responses against the defined specifications.
118
121
119
-
<aid="six"></a>
120
-
## 5. API Test Execution
122
+
123
+
<aid="four"></a>
124
+
## 4. API Test Execution
121
125
This project uses **Maven** for dependency management and build automation. The base URL for the API tests can be configured by creating a hidden `.env` file and defining the `BASE_URL` parameter.
122
126
The default value is `http://localhost:3000/api/v1/`, but this setting can be modified directly within the `server.js` file.<br/>
123
127
@@ -137,8 +141,9 @@ mvn test -Dtest={String}
137
141
_Parameters:_<br/>
138
142
`-Dtest={String}` - name of Test class.<br/>
139
143
140
-
<aid="seven"></a>
141
-
## 6. Generate Allure REST Assured Report
144
+
145
+
<aid="five"></a>
146
+
## 5. Generate Allure REST Assured Report
142
147
Before running tests, it's crucial to clean up any existing test results and reports. This ensures that your report accurately reflects the most recent test run.
143
148
Use the following command to remove the `allure-report` and `allure-results` directories:
144
149
```bash
@@ -168,13 +173,14 @@ allure serve
168
173
```
169
174
This command starts a local web server and automatically opens the generated report in your default browser.
170
175
171
-
#####Allure Report Overview
172
-
An example of the generated Allure report looks like this:
176
+
### Allure Report Overview:
177
+
An example of the generated Allure report looks like this:<br/>
This project utilizes a CI/CD pipeline configured using GitHub Actions. The pipeline automates the testing process, ensuring that every code change is thoroughly validated.
179
185
The configuration file for the workflow is located at `.github/workflows/ci.yml`.
0 commit comments