When running my scripts using npx cypress open and selecting Firefox as the browser, my scrips are running without any issues, but when I run one of the following commands:
npx cypress run --spec "cypress/e2e/Feature Testing/" --browser firefox --headed
or
npx cypress run --spec "cypress/e2e/Feature Testing/" --browser firefox --headless
my scripts fail due to an error caused by the cypress-cucumber-preprocessor:
task cypress-cucumber-preprocessor:spec-envelopes, {messages: Array[7]}, {log: false}
CypressError:
cy.task()
must only be invoked from the spec file or support file.
Because this error occurred during abefore all
hook we are skipping the remaining tests in the current suite
My cypress.config.js file looks like this:
const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const addCucumberPreprocessorPlugin = require("@badeball/cypress-cucumber-preprocessor").addCucumberPreprocessorPlugin;
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild").createEsbuildPlugin;
module.exports = defineConfig({
e2e: {
async setupNodeEvents(on, config) {
// implement node event listeners here
const bundler = createBundler({
plugins: [createEsbuildPlugin(config)],
});
on("file:preprocessor", bundler);
await addCucumberPreprocessorPlugin(on, config);
return config;
},
specPattern: "**/*.feature",
chromeWebSecurity: false,
experimentalOriginDependencies: true,
},
retries: {
runMode: 2
}
});
The other browsers (Chrome & Edge) are running without issues on both headed and headless mode and when running both ‘npx cypress open’ and ‘npx cypress run’. How could I resolve this issue on Firefox?