Automate Rest API using java with postman

Hi All,

I am new to API testing.I am trying to Automate the API using postan but dont know how to automate the API with postman using java.Please let me know how to process in this.
I googled it but didn’t found a solution.

Hope I will find my answer here and I will very thankfull to you guys.

Thanks & regards
Bibhu Pandey

Hi @bibhuTest12,

Welcome to the community. :wave:

Automating your API tests with Postman is possible using JavaScript. It is the only supported language to write per-request and test scripts in Postman.

Here are some useful resources to get started:

# How write API Tests with Postman: (Valentin Despa)

# Intro to Postman:

# Automate test runs using Newman:

# Articles:

2 Likes

Hey Suraj,

Thanks for sharing the helpfull content.
Thanks a lot.

Regards
Bibhu Pandey

Hi @bibhuTest12,

Looks like you are trying to use Postman JavaScript tools to do some automation. I’d recommend the above videos and you can also look at this pre request and test script video I made:

Postman Pre Request and Test Scripts Tutorial - Introduction to Postman https://youtu.be/NA2nfftMC5E

Additionally, you can watch the whole intro series I made for a good basis on Postman.

Introduction to Postman Tutorial https://www.youtube.com/playlist?list=PLtnFhV9xWljfvww1P_fNgb0cnA4H-zmZQ

Now if you’re trying to use Java to run Postman requests, you can do so via Postman’s api and building requests in Java from Postman. Or you can use Newman that you can kick off from your Java code.

If you can elaborate a bit more on how you’re trying to run the automation, I’d be more than happy to provide more details :blush:.

Regards,
Orest

1 Like

Hello,
I have a use case, I hope you can help me here.

We are using karate framework for API testing. As this is built on top of Cucumber, it requires creating feature files. Everything was working well.

Now, we had a requirement where we need to run the postman collections as it is. Karate supports generating the feature files on the basis of collection provided, but it skips the tests and pre-request scripts.

We are thinking to revise our approach here,
Requirements are.

  1. need to run postman collection.
  2. all the tests and pre-requests script should run and if any assertion fails, it should report it back.
  3. the reporting should be more detailed oriented.

I have come across newman and seems like a good fit, but can we generate cucumber/testng/junit type of reports with it ?

Can we use java based solution for this ? Installing the newman package and running it in using Runtime library, is this a good practice to have in project ?

As we are taking the requirement 1) as the topmost priority and this is directly connected with the postman, what alternates can we suggest for this requirement ?

Welcome to the community @shubhDcoder :clap:

To be honest, I am not that familiar with this. If you definitely need to run the postman collection, and automatically running tests, then I certainly recommend using newman.

Doing a quick search, I couldnt seem to find specific cucumber/junit reports, but @danny-dainton wrote a great HTML reporter that you may find useful.

I am not certain of what you mean here, if you are saying to invoke Newman via Java code, I don’t see a problem with that. However, it might be better to use CI/CD pipeline tools like Jenkins that can automatically run these tests after a build, when configured to do so.

As for other reporting alternatives, I’m not sure what else there really is, but there are other packages out there that do reporting.

Now, I’m if Cucumber / junit can import test results, then you could, in theory write your own reporter based on the output of newman (as @danny-dainton did), so that it matches the expected input for Cucumber / junit, and simply upload the resulting file to cucumber / junit for recording test results.

Hope this helps!