Code Monkey home page Code Monkey logo

newman-reporter-xunit's Introduction

newman-reporter-xunit

JUnit reporter for Newman that provides the information about the collection run in JUnit format. This needs to be used in conjunction with Newman so that it can recognize JUnit reporting options.

JUnit Reporter based on XSD specified by Publish Test Results task for Azure Pipeline | TFS 2018 | TFS 2017 | TFS 2015

Different from newman-reporter-junit is using executions to have full report and no aggregated report. Please use newman-reporter-junit if you want the original aggregated results. This is based on [newman-reporter-junitfull] (https://github.com/martijnvandervlag/newman-reporter-junitfull) while adding some features

Install

The installation should be global if newman is installed globally, local otherwise. (Replace -g from the command below with -S for a local installation)

$ npm install -g newman-reporter-xunit

Usage

The examples provided in the usage are for showing the differences between newman-reporter-junit and this project.

Iteration (-n 2) is used to show the difference between original and full reports.

JUnit examples can be found here.

Original

Use newman-reporter-junit to execute.

In order to enable this reporter, specify junit in Newman's -r or --reporters option.

newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv -r junit --reporter-junit-export './examples/original/result.xml' -n 2

Full

In order to enable this reporter, specify xunit in Newman's -r or --reporters option.

newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv -r xunit --reporter-xunit-export './examples/full/result.xml' -n 2

Change request named

When using data file from newman, the same request, for each iteration, will have the same name, which is not very readable to distinguish the various test cases present in data file.

You can then set a special global variable which will change this name

pm.globals.set("__name__" + pm.info.iteration + pm.info.requestName, <new name>)

This way, the name can depend on data present (e.g: 'testName') in datafile

pm.globals.set("__name__" + pm.info.iteration + pm.info.requestName, pm.iterationData.get("testName"))

Change package name

It's the same principle as above, you can set the Iteration name (by default 'Iteration x') to an other name so that they are more readable

pm.globals.set("__name__" + pm.info.iteration, <new name>)

Options

With Newman CLI

CLI Option Description
--reporter-xunit-export <path> Specify a path where the output XML file will be written to disk. If not specified, the file will be written to newman/ in the current working directory.
--reporter-xunit-hideSensitiveData Ask reporter to remove any property containing 'user', 'password', 'token', 'usr', 'pwd', 'passwd' so that these data do not leak through report
--reporter-xunit-excludeRequest <req1>,<req2> Exlude the named requests from report
--reporter-xunit-aggregate Include failure and error count totals at the root testsuites node

With Newman as a Library

The CLI functionality is available for programmatic use as well.

const newman = require('newman');

newman.run({
    collection: require('https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv'), // can also provide a URL or path to a local JSON file.
    reporters: 'xunit',
    reporter: {
        xunit: {
            export: './examples/full/result.xml', // If not specified, the file will be written to `newman/` in the current working directory.
        }
    },
	iterationCount: 2
}, function (err) {
	if (err) { throw err; }
    console.log('collection run complete!');
});

Compatibility

newman-reporter-xunit newman node
v1.0.0 >= v4.0.0 >= v6.x

Troubleshooting

Reporter not found

The reporter and newman must be installed at the same level, the installation should be global if newman is installed globally, local otherwise.

Getting different JUnit output

You are most probably getting in-built reporter output used in older versions of newman, Please check the newman's compatibility section above.

If you are facing any other problem, please check the open issues or create new.

Community Support

If you are interested in talking to the Postman team and fellow Newman users, you can find us on our Postman Community Forum. Feel free to drop by and say hello. You'll find us posting about upcoming features and beta releases, answering technical support questions, and contemplating world peace.

Sign in using your Postman account to participate in the discussions and don't forget to take advantage of the search bar - the answer to your question might already be waiting for you! Don’t want to log in? Then lurk on the sidelines and absorb all the knowledge.

License

This software is licensed under Apache-2.0. Copyright Postdot Technologies, Inc. See the LICENSE file for more information.

newman-reporter-xunit's People

Contributors

bhecquet avatar martijnvandervlag avatar naasse avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

newman-reporter-xunit's Issues

Add total failures and errors count to root element "testsuites"

This is an enhancement request.

I believe this would be universally helpful - it might be useful to have the aggregated total failure and error count at the root testsuites element.

To avoid breaking changes for consumers, this probably deserves a flag to only apply optionally.

It's something I would like to see in my use case, so I'm going to update my fork and create a PR if you'd like it in the core product.

avoid getting the same request name for each iteration

Using a data file, it should be possible to write

pm.globals.set("__name__" + pm.info.iteration + pm.info.requestName, pm.iterationData.get("testName"))

And then, request display name would be set to the name from data file

Error: Missing attribute value. attribute: {value}, parent: <property> when a used environment variable is not set

This stems from the original repo:
martijnvandervlag#2

I have a collection suite to test my API where I often will run pre-request scripts to setup some data before my request and tests.
Sometimes, I set an environment variable inside my prerequest script that gets used in the request URL. Most notably, if I create an API resource, I might take the GUID from the response and request a PUT or DELETE to that resource in my test.

If for some reason the pre-request were to fail, the entire report crashes. Rather than getting a failure report for that test, I get an empty report back due to the null pointer.

`C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:121
property.att('value', propertyItem.value.substring(0, 70));
^

TypeError: Cannot read properties of null (reading 'substring')
at C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:121:47
at arrayEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:530:11)
at Function.forEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:9410:14)
at C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:89:7
at arrayEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:530:11)
at Function.forEach (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\node_modules\lodash\lodash.js:9410:14)
at EventEmitter. (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman-reporter-xunit\lib\index.js:72:5)
at EventEmitter.emit (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\eventemitter3\index.js:203:33)
at done (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\lib\run\index.js:314:29)
at C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\backpack\index.js:58:34
at PostmanCollectionRun._process (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\run.js:163:13)
at PostmanCollectionRun. (C:\Users\naasse\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\run.js:169:76)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)`

It's an easy fix, we just need a null check there. If it's set to the empty string instead of null, XMLAttribute will parse it fine and the reporter will carry on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.