3

I want to classified tests to run them for different purposes. As far as, I search I could not an option to tag some test and run test on demand. I also looked at Chaijs if it has such a feature, but could not be able to find a solution.

What I want to do is add some tag like the following:

@health_check
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

@smoke
pm.test("Product should be correct", function () {
    var jsonData = pm.response.json();
    var product = pm.variables.get("PRODUCT");

    pm.expect(jsonData.meta.appId).to.eql(product);
});

and run it like as following or anyway achieve this:

$ newman run mycollection.json -tag smoke
Mesut GUNES
  • 7,089
  • 2
  • 32
  • 49

1 Answers1

3

That tag type option is not something that's ever been available in the app or in Newman.

You could use the --folder option on the CLI and organise your collections to include requests within those specific folders, that cover those scenarios.

For example:

$ newman run mycollection.json --folder healthCheck --folder smoke

Alternatively, you could use a global variable to act as a switch in the control if specific tests/groups of tests are run.

Wrapping the test in an if statement like this:

if(pm.globals.get('smoke_check') === "runCheck") {
    pm.test("Status code is 200", () => pm.response.to.have.status(200));
}

Then passing in a global variable in the cli using the --global-var flag.

$ newman run mycollection.json --global-var "smoke_check=runCheck"

n-verbitsky
  • 552
  • 2
  • 9
  • 20
Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • thanks for the answer, folder option seems good but it needs replication of the requests if we want to assert different things for different purposes. – Mesut GUNES Jan 10 '20 at 08:38
  • Maybe you could control that via a variable? You can pass those in as an arg from the command line, that could act as a switch to run/not run a certain set of tests as part of the run? – Danny Dainton Jan 10 '20 at 09:02
  • 2
    @MesutGÜNEŞ I update the answer with a simple example to show this. Hope that helps. – Danny Dainton Jan 10 '20 at 10:02