project report generation - Notes By ShariqSP
Installing Node.js
Introduction
Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine, enabling server-side JavaScript execution. It’s essential for running applications like Newman, the CLI tool used with Postman, and for building server-side and full-stack JavaScript applications.
Here, we cover the installation steps for Node.js on Windows, macOS, and Linux.
Step-by-Step Installation Guide
1. Installing Node.js on Windows
- Visit the Node.js website and download the Windows installer (the .msi file) for the latest LTS (Long-Term Support) version.
- Run the downloaded installer. Follow the prompts, and ensure you select the option to automatically install necessary tools.
- Verify the installation by opening a Command Prompt and typing the following commands to check the versions:
node -v npm -v
This confirms that Node.js and npm (Node Package Manager) are installed successfully.
2. Installing Node.js on macOS
You can install Node.js on macOS via the Node.js installer or using the Homebrew
package manager.
Method 1: Using the Node.js Installer
- Go to the Node.js website and download the macOS installer (.pkg file).
- Run the installer and follow the prompts.
- Open a terminal and verify the installation by running:
node -v npm -v
This will display the installed versions of Node.js and npm.
Method 2: Using Homebrew
If Homebrew is installed, you can install Node.js with the following command:
brew install node
After installation, verify by running node -v
and npm -v
in the terminal.
3. Installing Node.js on Linux
On Linux, you can install Node.js using your package manager, or you can use NodeSource’s PPA for the latest versions.
Method 1: Using the Package Manager (Ubuntu/Debian)
- First, update your package list:
sudo apt update
- Install Node.js with:
sudo apt install nodejs sudo apt install npm
- Verify the installation by checking the versions:
node -v npm -v
Method 2: Using NodeSource’s PPA (Recommended for Latest Versions)
- Download and install the NodeSource PPA setup script for the latest version of Node.js:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
- Once the PPA is added, install Node.js with:
sudo apt install -y nodejs
- Confirm the installation with:
node -v npm -v
Configuring Node.js and npm (Optional)
Node.js is now ready for use. If you need to install packages globally (like Newman), you may want to configure npm to avoid permission issues by setting up a global installation directory. This configuration is helpful for installing packages without sudo
on Unix systems.
Set Up a Global npm Directory
- Create a directory for global npm packages:
mkdir ~/.npm-global
- Configure npm to use this directory:
npm config set prefix '~/.npm-global'
- Add the new directory to your PATH by editing
~/.profile
:export PATH=~/.npm-global/bin:$PATH
- Activate the changes with:
source ~/.profile
Conclusion
Following these steps will successfully install Node.js and npm on your system, allowing you to develop JavaScript applications and install packages like Newman for running Postman collections from the command line.
Project Report Generation in Postman
Introduction to Project Report Generation
Generating a report in Postman allows teams to document API testing results comprehensively. Reports provide insights into which tests passed or failed, helping developers and QA teams identify issues and track test coverage and stability over time. This reporting feature is especially useful for project reviews, tracking regressions, and verifying that updates don’t break existing functionality.
Using Postman’s Reporting Features
Postman offers report generation through its Collection Runner and Newman CLI. Reports can be generated and exported to various formats, such as JSON, HTML, or XML, and they contain details on request-response times, test results, assertions, and more. The most common way to create detailed reports is by using Newman, which provides advanced reporting capabilities and customization options.
Generating Reports with Collection Runner
The Collection Runner in Postman allows you to execute a collection and view the results within the Postman application. However, this approach is limited to visual analysis in Postman and is less suitable for exporting detailed reports. Here’s how to run a collection in the Collection Runner:
- Open Postman and select the collection you want to test.
- Click on Run to open the Collection Runner.
- Set environment variables if required and configure the number of iterations, delays, etc.
- Click on Run {{collection_name}} to execute the tests.
- Once completed, view the results directly in Postman’s Collection Runner window.
While this method is useful for quick feedback, it doesn’t generate a standalone report. For exporting and detailed reports, Newman is recommended.
Generating Reports with Newman
Newman is Postman’s CLI tool, which enables running Postman collections from the command line and supports more detailed and customizable reporting options. To use Newman, ensure that Node.js is installed, as Newman is installed via npm.
Step 1: Install Newman
npm install -g newman
Step 2: Run the Collection with Newman and Generate a Report
Use the command below to run a collection and generate a basic JSON report:
newman run {{path_to_collection}}.json -e {{path_to_environment}}.json -r json
In this command:
{{path_to_collection}}
is the path to the Postman collection file.{{path_to_environment}}
is the path to the environment file (optional).-r json
specifies the report format as JSON.
Step 3: Generating HTML Reports
For a more user-friendly report, use Newman’s HTML reporting option. Newman supports an HTML reporter called newman-reporter-html
that needs to be installed separately.
npm install -g newman-reporter-html
Once installed, run the following command to generate an HTML report:
newman run {{path_to_collection}}.json -e {{path_to_environment}}.json -r html
The HTML report provides a detailed view of each request, response, and assertion. It’s ideal for sharing with stakeholders who need to review test results in a clear, visual format.
Customizing Reports in Newman
Newman also allows additional customization options. Here are some key flags and options:
Option | Description |
---|---|
--reporter-html-export <path> |
Exports the HTML report to a specified path, enabling easy sharing and archival. |
--reporter-json-export <path> |
Exports the JSON report, which can be parsed and used programmatically in dashboards or CI/CD pipelines. |
--reporter-htmlextra |
Installs and uses the newman-reporter-htmlextra for a more detailed and customizable HTML report. |
Here’s an example of generating an enhanced HTML report using newman-reporter-htmlextra
:
npm install -g newman-reporter-htmlextra
newman run {{path_to_collection}}.json -e {{path_to_environment}}.json -r htmlextra --reporter-htmlextra-export ./report.html
This generates a more detailed HTML report, including request headers, response bodies, and additional test information, ideal for in-depth project analysis.
Project Report Automation in CI/CD Pipelines
For continuous integration workflows, Newman can be integrated into CI/CD pipelines (e.g., Jenkins, GitLab CI, GitHub Actions) to automate report generation and analysis on each code update. This setup allows teams to continuously monitor API health and identify issues early.
Example Jenkins Configuration for Automated Reports
pipeline {
agent any
stages {
stage('Run API Tests') {
steps {
script {
sh 'newman run {{path_to_collection}}.json -e {{path_to_environment}}.json -r htmlextra --reporter-htmlextra-export ./newman/report.html'
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'newman/report.html', allowEmptyArchive: true
}
}
}
This Jenkins pipeline executes the Newman tests, generates an HTML report, and archives it as part of the build artifacts for easy access and review.
Conclusion
Project report generation in Postman, especially using Newman, allows teams to document and share API testing results effectively. Reports help in identifying issues, tracking test coverage, and ensuring continuous API reliability, making them essential for both development and QA teams.