This Node.js script utilizes Newman to run a Postman collection, capturing and storing response data, while handling CSV data and optionally using SSL certificates.
- Node.js installed on your machine. You can download it from here.
- Postman collection file (
sample-collection.json
) in the project directory. - SSL certificates (
test.crt
,test.key
,test.pem
) for secure requests (optional). - Iteration data in CSV format (
TEST_DATA.csv
).
-
Clone the repository:
git clone https://github.com/yourusername/your-repository.git
-
Install dependencies:
npm install
-
Configure the script by setting the appropriate values in the
newmanOptions
object inscript.js
:collection
: Path or URL to the Postman collection JSON file.sslClientCert
,sslClientKey
,sslClientPem
: Paths to SSL certificate files (optional).sslClientPassphrase
: Passphrase for the SSL certificate (optional).iterationData
: Path to the CSV file containing iteration data.
-
Run the script:
node .\save-response.js
The Newman run is configured to:
- Use iteration data from a CSV file (
TEST_DATA.csv
) to provide dynamic inputs. - Optionally perform requests with SSL certificates for secure communication.
Assuming the CSV file (TEST_DATA.csv
) has the following structure:
Copy code
post_id
1
2
3
4
5
The provided sample collection (sample-collection.json
) contains a request named "SEND_SMS_SAMPLE" that uses the Postman variable {{post_id}}
to dynamically replace the post ID in the request URL.
{
"item": [
{
"name": "SEND_SMS_SAMPLE",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://jsonplaceholder.typicode.com/posts/{{post_id}}",
"protocol": "https",
"host": ["jsonplaceholder", "typicode", "com"],
"path": ["posts", "{{post_id}}"]
}
},
"response": []
}
]
}
- The script generates a CSV file (
response.csv
) with the response data for each request. - The raw response data for the last request is stored in
response.txt
.
- If SSL certificates are not needed, you can remove the SSL-related configuration options (
sslClientCert
,sslClientKey
,sslClientPem
,sslClientPassphrase
) from thenewmanOptions
object inscript.js
. - Ensure that the Postman collection is correctly configured.
- Replace placeholder values in the
newmanOptions
object with your actual values.