michaelruocco / gradle-postman-runner

A gradle plugin to run Postman collections
MIT License
16 stars 13 forks source link

Add support to pass argument to newman while running "gradle-postman-runner" plugin #8

Closed Abhishek9701 closed 3 years ago

Abhishek9701 commented 6 years ago

I am trying to run the collections from local machine(that is the requirement as of now), I need to disable the SSL Certificate during execution as most of our server’s access is restricted from local machine. I came to know that we can instruct newman to disable strict SSL by using this command: --insecure. But how can I pass this command to newman while using your gradle plugin? TIA.

RyanKys commented 6 years ago

Below is my dirty tricks to get "--insecure" works. The code below overrides the default DeployNewmanWrapperTask so that it won't inject the default startnewman.js, and customizes it by adding config.insecure=true.

It's not a good solution, but can be temporary used as a walkaround until the author release a new version to support insecure flag.

import de.infonautika.postman.PostmanExtension import de.infonautika.postman.task.* import de.infonautika.postman.newman.* import com.moowork.gradle.node.*

apply plugin: CustomizedPostmanRunnerPlugin

class CustomizedPostmanRunnerPlugin implements Plugin<Project> { public void apply(Project project) { project.task(type(PostmanTask.class), PostmanTask.NAME); // Comment out the default implementation of DeployNewmanWrapperTask //project.task(type(DeployNewmanWrapperTask.class), DeployNewmanWrapperTask.NAME); project.getExtensions().create(PostmanExtension.NAME, PostmanExtension.class, project); } private <T> Map<String, Class<T>> type(Class<T> clazz) { HashMap<String, Class<T>> map = new HashMap<>(); map.put("type", clazz); return map; } }

// ******************************************************* // Install newman globally // ******************************************************* task installNewman (type: NpmTask){ workingDir = file '../' args = ['install','-g','newman'] }

// ******************************************************* // Override the plugin deployWrapper task by injecting config.insecure=true to support self-sign cert. // ******************************************************* task deployWrapper{ doLast { def wrapperFile = file(new NewmanWrapper(getProject()).getWrapperRelativePath()) mkdir wrapperFile.getParent() wrapperFile.text = """ "use strict"; const newman = require('newman'); var config = JSON.parse(unescape(process.argv[2]).replace(new RegExp('<>', 'g'), '"')); config.insecure=true; newman.run(config, function(err, summary) { if (err) { console.log(JSON.stringify(err, null, 1)); process.exit(2); } else { if (summary.run.failures && summary.run.failures.length > 0) { process.exit(1); } } });""" } }

michaelruocco commented 3 years ago

I actually added support for the insecure flag a while back so I am closing this down.