# HTML Reporter with all optionsnewmanruncollection.json\-rhtml\--reporter-html-export./reports/report.html\--reporter-html-template./template.hbs\--reporter-html-title"API Test Report"# JSON Reporternewmanruncollection.json\-rjson\--reporter-json-export./reports/output.json
# JUnit Reporternewmanruncollection.json\-rjunit\--reporter-junit-export./reports/junit.xml
# CLI Reporter (suppress specific outputs)newmanruncollection.json\-rcli\--reporter-cli-no-summary\--reporter-cli-no-failures
#!/bin/bash# Jenkins/GitLab CI script for API testing# Run collection with environmentnewmanrunapi-tests.json\-eproduction.json\-rcli,junit\--reporter-junit-export./test-results/junit.xml\--bail\--suppress-exit-code
# Check exit codeif[$?-eq0];thenecho"All tests passed"exit0elseecho"Tests failed"exit1fi
# Test multiple user scenarios from CSVnewmanrunuser-registration.json\-duser-data.csv\-estaging.json\-rhtml,cli\--reporter-html-export./reports/registration-tests.html\--delay-request500\--timeout-request15000
#!/bin/bash# Test across multiple environmentsENVIRONMENTS=("dev""staging""production")forenvin"${ENVIRONMENTS[@]}";doecho"Testing $env environment..."newmanruncollection.json\-e"environments/${env}.json"\-rhtml\--reporter-html-export"./reports/${env}-report.html"\--bail
if[$?-ne0];thenecho"Tests failed in $env environment"exit1fidoneecho"All environments tested successfully"
#!/bin/bash# Cron job for API health monitoring (run every 15 minutes)# */15 * * * * /path/to/api-monitor.shDATE=$(date+%Y%m%d-%H%M%S)newmanrunhealth-check.json\-eproduction.json\-rjson,html\--reporter-json-export"./logs/health-${DATE}.json"\--reporter-html-export"./logs/health-${DATE}.html"\--timeout-request5000\--suppress-exit-code
# Send alert if tests failif[$?-ne0];thenecho"API health check failed at ${DATE}"|mail-s"API Alert"admin@example.com
fi
// test-runner.jsconstnewman=require('newman');newman.run({collection:require('./collection.json'),environment:require('./environment.json'),reporters:['cli','html','json'],reporter:{html:{export:'./reports/report.html'},json:{export:'./reports/report.json'}},iterationCount:3,delayRequest:500,timeout:10000},function(err,summary){if(err){console.error('Collection run failed:',err);process.exit(1);}console.log('Collection run complete!');console.log('Total requests:',summary.run.stats.requests.total);console.log('Failed requests:',summary.run.stats.requests.failed);console.log('Test failures:',summary.run.stats.tests.failed);// Exit with error code if tests failedif(summary.run.stats.tests.failed>0){process.exit(1);}});
Use Environment Variables: Almacene datos sensibles (clave API, contraseñas) en archivos ambientales, nunca código duro en colecciones
Implement Proper Timeouts: Establecer valores realistas __INLINE_CODE_61_ basado en los tiempos de respuesta esperados de su API para evitar fallos falsos
Permitir información detallada: Utilice múltiples reporteros (-r cli,html,junit) para obtener resultados de prueba integrales e integración CI/CD
Version Control Your Collections: Exportar colecciones de Postman y almacenar en Git junto con su base de código para el seguimiento de la versión
Utilice archivos de datos para escalabilidad: Leverage CSV/JSON ficheros de datos con la bandera __INLINE_CODE_63_ para probar múltiples escenarios sin duplicar solicitudes
Implement Retry Logic: Para pruebas descaradas, envuelve comandos de newman en los bucles de retry o utiliza mecanismos de retry CI/CD
Organizar Colecciones por Propósito: Separar pruebas de humo, pruebas de regresión y pruebas de integración en diferentes colecciones para la ejecución selectiva
Resultados del informe y del archivo: Utilizar siempre --export-environment y --export-globals para capturar el estado del tiempo de ejecución para depurar
Certificados SSL seguros: Use --ssl-client-cert y --ssl-client-key para la prueba de API autenticada, evite --insecure en producción
Monitor Performance: Seguimiento de los tiempos de ejecución en los informes para identificar puntos finales lentos y posible degradación del rendimiento
# Using Postman API to export collectioncurl-XGET\'https://api.getpostman.com/collections/<collection-uid>'\-H'X-Api-Key: <your-postman-api-key>'\-ocollection.json
# Run exported collectionnewmanruncollection.json
# Run with custom reporternewmanruncollection.json-rhtmlextra
# HTMLExtra with optionsnewmanruncollection.json\-rhtmlextra\--reporter-htmlextra-export./report.html\--reporter-htmlextra-darkTheme\--reporter-htmlextra-title"Custom API Tests"
# Using GNU Parallel for concurrent executionparallel-j4newmanrun:::\auth-tests.json\user-tests.json\order-tests.json\payment-tests.json
# Using background jobsnewmanruncollection1.json-eenv1.json&\newmanruncollection2.json-eenv2.json&\newmanruncollection3.json-eenv3.json&\waitecho"All collections completed"