Steps to automate API testing using Postman, Newman, and Jenkins

Steps to automate API testing using Postman, Newman, and Jenkins


As APIs become increasingly complex, it becomes crucial to ensure their reliability and functionality through comprehensive testing. To streamline this process, automation tools such as Postman, Newman, and Jenkins have emerged as powerful solutions. Here are some steps to use these tools together:

  1. Create API requests and test scripts in Postman:

a. Use Postman's user-friendly interface to design API requests and define test scripts.

b. Validate response data, status codes, and headers using Postman's built-in testing capabilities.

2. Export Postman collections and environments:

a. Save the collections and environments as JSON files for future use.

b. These files will be utilized by Newman for command-line execution.

3. Setting up Jenkins for API testing automation:

a. Install the necessary plugins in Jenkins for API testing and integration with Postman.

b. Configure Jenkins jobs to execute Newman commands, utilizing the exported collections and environments.

4. Scheduling and monitoring API test runs:

a. Utilize Jenkins to schedule regular API tests or trigger them based on specific events or criteria.

b. Monitor and analyze test results through the test reports generated by Newman, identifying potential issues. Newman supports html formatters that can be installed in jenkins and used along jenkins pipeline.

e.g newman run myapicollection.postman_collection.json -d inputdata.json -r htmlextra --reporter-htmlextra-export ./report.html

c. For html publishing and viewing of newman report in html format, html publisher can be used https://plugins.jenkins.io/htmlpublisher/ this can take input a html report generated in step above and generate a nicely formatted report

No alt text provided for this image

* A minor problem still exist where the generated html report does not display at first, discussed here https://community.postman.com/t/newman-htmlextra-reporter-not-displaying-correctly-when-viewed-from-jenkins/5735/2.

To resolve that run in script console at Manage Jenkins -> Node -> Built In Node-> Script Console:

System.setProperty(?"hudson.model.DirectoryBrowserSupport.CSP"?,?""?)

This temporarily allows css display but goes away after reboot :)

5. Integrating with CI/CD pipelines:

a. Incorporate API testing as an essential step in your CI/CD process to ensure the quality of your software.

b. Utilize the test results obtained from API testing to make informed decisions about the deployment process.

Arjun Menon

2x Founder Now Building Chi AI | Techstars ‘23

1 年

Anju Shrestha great post, but maintenance and scalability of postman based test are low. We are trying to solve by building Chi. Check out https://thechi.app and join the wait list for an early access. We begin where postman ends :)

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了