postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.84k stars 839 forks source link

Running Newman: command line works, Javascript throws an error #10723

Closed hflocken closed 2 years ago

hflocken commented 2 years ago

Is there an existing issue for this?

Describe the Issue

Hi,

I have a collection that I can run successfully using the following command: newman run --verbose --insecure --ssl-client-cert /Volumes/Certs/cert.pem --ssl-client-key /Volumes/Certs/key.pem Tester.postman_collection.json -e Default.postman_environment.json –reporters cli

As I would like to capture the response body of the request, I'm trying to run Newman with the following script:

const newman = require('newman');
const fs = require('fs');

newman.run({
    collection: './Tester.postman_collection.json',
    reporters: 'cli',
    insecure: true,
    sslclientcert: '/Volumes/Certs/cert.pem',
    sslclientkey:  '/Volumes/Certs/key.pem',
    environment:   './Default.postman_environment.json'
}).on('beforeRequest', function (error, args) {
    if (error) {
        console.error(error);
    } else {
        // Log the request body
        console.log(args.request.body.raw);
    }
}).on('request', function (error, args) {
    if (error) {
        console.error(error);
    }
    else {
        // Log the response body
        console.log(args.response.stream.toString());
    }
});

However, in this case I get an error about an assertion that fails.

If would appreciate if somebody could give me a hint what the difference is between the two invocations and why the second one is failing.

Steps To Reproduce

Run the two invocations that are described above.

Screenshots or Videos

No response

Environment Information

- Operating System: Mac
- Platform Type: Newman 5.3.0, Node v17.1.0
- Postman Version: n/a

Additional Context?

No response

DannyDainton commented 2 years ago

Hey @hflocken

This is the repo for the Postman app/desktop platforms.

Could you please raise this in the Newman repository.

https://github.com/postmanlabs/newman


Something to check on would be the names you're using in the script, as per the documentation it would be these.

sslClientCert
sslClientKey
hflocken commented 2 years ago

@DannyDainton thanks for the hint - that already fixed my problem