Maven plugin for Proxy deployment and running POSTMAN test cases

ankitmadho
Participant II

I want to deploy a proxy and then post-deployment I want to run test cases in POSTMAN only. Is there a way that it can be run in one command. I don't want to use Junit or SOAP UI or any other tool for testing

Solved Solved
0 4 3,872
1 ACCEPTED SOLUTION

HI @Ankit Madhogaria

You should be using Newman which is what Postman uses behind the scenes to execute the test cases in your postman collection. For more info, check this link.

To execute this using the Maven pom, you first need to make sure the machine executing the pom has NodeJS installed as newman used in my code is using newman npm

Include a package.json file in your proxy project, the file should include

{
	"name": "some-proxy",
	"version": "1.0.0",
	"dependencies": {
		"newman": "^4.3.0",
		"prettyjson": ">=1.1.3",
		"jsonfile": ">=2.3.1",
		"lodash": ">=4.15.0",
		"bluebird": "^3.3.5"
	}
}

Note: I have included many other npm dependencies which you might not need

In your pom.xml, include these lines of code. The first execution contains the installation of node modules from the package.json and then running the newman module by passing the path of the postman collection and environment json.

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <!-- npm install -->
          <execution>
            <id>npm-install</id>
            <phase>test</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <commandlineArgs>
                install
              </commandlineArgs>
            </configuration>
          </execution>
          <!-- Integration Testing-->
          <execution>
            <id>integration-tests</id>
            <phase>install</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>node_modules/newman/bin/newman.js</executable>
              <commandlineArgs>
                run target/test/integration/oauth.postman_collection.json -e target/test/integration/oauth.postman_environment.json
              </commandlineArgs>
            </configuration>
          </execution>
        </executions>
      </plugin>

Try this out and see if it works

View solution in original post

4 REPLIES 4

sidd-harth
Participant V

Well try using Apigee Maven plugin for deployments and use Newman for using Postman testing.

Newman is a command line Collection Runner for Postman. It allows you to run and test a Postman Collection directly from the command line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.

No Sir, I cannot. I only have the option of using POSTMAN. If you can please help me automate the build, deploy and testing using only Maven and POSTMAN it would be really very helpful. If you know of any websites or plugins which might help me.

HI @Ankit Madhogaria

You should be using Newman which is what Postman uses behind the scenes to execute the test cases in your postman collection. For more info, check this link.

To execute this using the Maven pom, you first need to make sure the machine executing the pom has NodeJS installed as newman used in my code is using newman npm

Include a package.json file in your proxy project, the file should include

{
	"name": "some-proxy",
	"version": "1.0.0",
	"dependencies": {
		"newman": "^4.3.0",
		"prettyjson": ">=1.1.3",
		"jsonfile": ">=2.3.1",
		"lodash": ">=4.15.0",
		"bluebird": "^3.3.5"
	}
}

Note: I have included many other npm dependencies which you might not need

In your pom.xml, include these lines of code. The first execution contains the installation of node modules from the package.json and then running the newman module by passing the path of the postman collection and environment json.

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <!-- npm install -->
          <execution>
            <id>npm-install</id>
            <phase>test</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <commandlineArgs>
                install
              </commandlineArgs>
            </configuration>
          </execution>
          <!-- Integration Testing-->
          <execution>
            <id>integration-tests</id>
            <phase>install</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>node_modules/newman/bin/newman.js</executable>
              <commandlineArgs>
                run target/test/integration/oauth.postman_collection.json -e target/test/integration/oauth.postman_environment.json
              </commandlineArgs>
            </configuration>
          </execution>
        </executions>
      </plugin>

Try this out and see if it works

Many thanks @Sai Saran Vaidyanathan, above solution works perfectly fine.