Cypress 10 -If a feature file is repeated more than once in specPattern , the feature file is running only once

94 Views Asked by At

I need feature1.feature to run three times as displayed in cypress.config.js . But while running npx cypress run --config-file cypress.config.js ` the feature1.feature is running only once. Is there any way I can Update the config file to run all feature1.feature.

const { defineConfig } = require("cypress");
const cucumber = require("cypress-cucumber-preprocessor").default;
module.exports = defineConfig({
  env: {
    url: "https://dev-abc.com/",
  },
  
  e2e: { 
    setupNodeEvents(on, config) {
      on('file:preprocessor', cucumber())
    },
    
    specPattern: 
    [ 
      "**/feature1.feature",
      "**/feature2.feature",
      "**/feature3.feature",
      "**/feature1.feature",
      "**/feature4.feature",
      "**/feature1.feature"
    ],
     testIsolation: false 
    },
  defaultCommandTimeout: 10000,
videosFolder: 'cypress/reports/folder1/mochawesome/videos',
screenshotsFolder: 'cypress/reports/folder1/mochawesome/screenshots',
  reporter: "mochawesome",
  sample: "value",
  reporterOptions: {
reportDir: 'cypress/reports/folder1/mochawesome/logs',
    overwrite: false,
    html: false,
    json: true,
  },
});

1

There are 1 best solutions below

1
On

I guess because specPattern is a pattern, when Cypress evaluates it you only get feature1 once in the (internal) list of specs to run.

You could try a comma-separated list at the CLI

cypress run --spec "cypress/e2e/feature1.feature,cypress/e2e/feature1.feature"

see if that invokes it twice.

Slightly less cumbersome is to create an "index" test

feature-list.feature

import "**/feature1.feature"
import "**/feature2.feature"
import "**/feature3.feature"
import "**/feature1.feature"
import "**/feature4.feature"
import "**/feature1.feature"

This works for vanilla js tests, maybe also for cucumber.

I have to add, it seems a bit strange to be repeating tests in a test run, unless you are coupling them - which generally is a bad practice.

If this is what you are doing, I suggest you forget this question and instead ask how to re-use parts of a test in other tests.