Skip to content

Repository files navigation

API Backend Automation Test

Project Overview

This project is designed for the digital.auto web application, but anyone can use this repo and modify the test methods to test the API Backend of any web pages. The way this automation test works is that it makes the https requests and check for the response status and data.

Written in JavaScript for the consistency with the backend codebase, this project also use the Jest Testing Framework, a popular testing framework for backend APIs.

Repository Structure

  • helper-functions/ : Contains utility functions for configuration, logging, proxy setup, and handling temporary files.
  • test-methods/ : Holds the test files. Each file should follow the .test.js naming convention for Jest to recognize it.
  • request-functions/ : Contains functions that handle HTTP requests. These are used in the test method files.
  • logs/ : Stores log files generated by each test method. This folder must exist even if it's initially empty.
  • temp-files/ : Stores temporary text files generated during testing. These files are created by temp-storage.js in the helper-functions folder. This folder must exist even if it's initially empty.
  • main.js : The entry point for running the tests. This file controls which test method files are executed. To run the project, simply type node main.js
  • info.js : Stores configurable settings like proxy details. Modify this file to adjust links and information for the test without changing the code.
  • package.json : Lists dependencies and scripts. Run npm install to install the necessary dependencies.

Adding New Test Methods

1. Creating Request Functions:

Add new HTTP request functions in the request-functions/ folder. Return these functions for use in the corresponding test method files in the test-methods/ folder.

2. Creating Test Files:

  • Place new test files in the test-methods folder. Follow the naming convention: yourTestName.test.js. Otherwise, the Jest testing framework won't recognize the test files.
  • Use the appropriate HTTP request functions from the request-functions/ folder.

Log Management

  • Logs are automatically generated for each test file (file that has naming convention yourTestName.test.js.) and saved in the logs/ folder.
  • Each test file creates its own log to prevent overly long log files. The name of the log file represents the date and time that the log is generated.

Proxy Setup

The project automatically detects when a proxy is needed based on your network.

  • Create an .env file and pass in the company domain name. The info.js will be updated according to the .env file. This field is required since the project checks if your computer is using the company's wifi network or not.
  • Modify the proxy port in the info.js if you need to use proxy.

Notes and Best Practices

  • Before doing anything, install all the dependencies, then create an .env file and make sure that all variables in info.js is declared in the environment file.
  • Ensure the order of test methods in main.js is correct, especially if tests depend on each other (e.g., creating a testing object in one file, but and deleting it in another file).
  • To see the DEBUG log lines, go to the logger.js file and modify this line let currentLogLevel = levels.INFO; into let currentLogLevel = levels.DEBUG;
  • Avoid hardcoding configuration details in test files; instead use info.js for flexibility.
  • The script --experimental-vm-modules --no-warnings in the package.json allow to generate the log separately for each test methods and prevent the unnecessary warnings of the Jest framework. Without --experimental-vm-modules, the main.js will have errors while executing.
  • Consider adding comments to your test files to describe the purpose and expected outcomes of each test.

Contact Information

Please contact my.giangvu@gmail.com if you need further assistance.

About

This project is an automation test designed for the backend of the digital.auto website, written in JavaScript & Jest framework

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages