Search code examples
protractorcucumbercucumberjs

Find tests that were not run as part of set tag list


I am looking for a way in CucumberJS to report which tests were not executed as part of a specific run.

Example: If my tags were ['@E2E', '~@higherEnvOnly'], I would like a report of which tests were excluded due to the ~@higherEnvOnly tag.

I have been able to get the list of all Features and Scenarios under each feature along with tags and names. I'm wondering if there's a report that would give me the excluded tests.

To give more perspective, the reason for the need is that the same set of tests may NOT be run every time as the list of features to be included (or excluded) is identified dynamically based on app configuration (specific to each environment we run the tests against). So it is important for us to find out which tests were run and which ones were excluded for each environment.


Solution

  • I was able to work around this by not passing the tags to exclude into the specs property, but rather using the Before hook to verify if the current scenario tag matches the excluded tag. Sample:

    In my config:

    base.config.cucumberOpts.specs = ['@E2E'];
    

    In hooks.ts:

    var excludedTag = '@tagToExclude';
    Before((scenario) => {
      var excludeScenario = false;
      scenario.pickle.tags.forEach(currTag => {
        if (currTag.name === excludedTag) {
          excludeScenario = true;
          break;
        }
      }
      return excludeScenario ? 'skipped' : '';
    });
    

    This ensures that the report actually shows @tagToExclude as skipped.