3

I have postman.collection.json files and I am able to run those collections files through newman and using the below command.

   newman run test.postman.collection.json -e environment.collection.json -d test.csv 

It ran successfully and is giving a response back.

I just want to get the same behavior by using the maven system. I need to integrate it with pom.xml, so that file will run the above collection.

Is this possible? If it's possible to run like this, then please share a sample to show how.

kc2001
  • 5,008
  • 4
  • 51
  • 92
ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84

2 Answers2

5

There are some unofficial postman runners for Maven, like this or this. I've never tried those, so I couldn't recommend either of them.

I prefer to use the maven-exec-plugin to run postman / newman collection during the integration-test or verify lifecycle phases.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>integration-tests</id>
            <phase>integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>
                    <!-- PATH_TO_NEWMAN_EXECUTABLE-->
                </executable>
                <commandlineArgs>
                    run <!--PATH_TO_COLLECTION_JSON--> -e <!--PATH_TO_ENVIRONMENT_JSON-->
                </commandlineArgs>
            </configuration>
        </execution>
    </executions>
</plugin>
kc2001
  • 5,008
  • 4
  • 51
  • 92
zforgo
  • 2,508
  • 2
  • 14
  • 22
  • 2
    Seems like a solution, but how can you check the test success? – Ceddoc Apr 23 '20 at 07:41
  • Maybe you would access to output report folder generated by extenal newman executions and read output files . – danipenaperez Jun 14 '22 at 14:28
  • 1
    @Ceddoc Newman can generate JUnit reports, therefore you can use that reports in the post-build actions and Jenkins can mark the build as failed or successful based on that reports. – Mr.Q Jul 20 '22 at 09:44
0

Additionally you can integrate newman available into Maven docker image and run as pipeline.

    spec:
  containers:
  - image: "miksonx/node-newman-maven"
    imagePullPolicy: "Always"
    name: "maven"
    tty: true
"""
...
   stages {
       stage('Unit Test') {
           agent{
               kubernetes {
                   yaml NodeNewmanMaven
               }
           }
           steps {
               container(MVN_AGENT) {
                   sh 'mvn clean integration-test'
               }
           }
    }

https://miksonx.wordpress.com/2021/04/19/postman-newman-using-maven-under-jenkins-kuberenets/