Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still remaining in firefox: cypresserror: cy.task() must only be invoked from the spec file or support file. #5533

Closed
1 of 6 tasks
wyattpuckett opened this issue Oct 11, 2023 · 2 comments

Comments

@wyattpuckett
Copy link

Description

Same as cypress-io/cypress#27099, I am seeing this error when executing tasks within my commands.js file, but only in firefox. Currently using 13.2, but has happened since 12.15

URL of Issue(s)

NA

Steps to replicate

  1. Use cypress version 12.15 or higher
  2. Have cy.task used within your commands.js file
  3. Execute the test in firefox
  4. Notice this error: cypresserror: cy.task() must only be invoked from the spec file or support file.

Example code from commands.js:
cy.contains('Sign in').click()
cy.task("generateOTP", 'example').then(token => {
cy.get("element").type(token);
cy.get('element').click()
})

Browser

Firefox 118.0.2

Device

  • PC
  • Mac
  • iPhone
  • iPad
  • Android Phone
  • Android Tablet

Additional Information

No response

@MikeMcC399
Copy link
Contributor

@wyattpuckett

The cy.task() > Usage example worked correctly for me on Cypress 13.2.0 and 13.3.0 running on Ubuntu 22.04 with Firefox 118

// in test
cy.task('log', 'This will be output to the terminal')

cypress.config.js

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('task', {
        log(message) {
          console.log(message)

          return null
        },
      })
    },
  },
})

This is actually the issue list for documentation and as far as I can see, the documentation https://docs.cypress.io/api/commands/task is correct.

If you need to report a bug with Cypress itself, that would belong in the https://github.com/cypress-io/cypress/issues list.

@wyattpuckett
Copy link
Author

Sounds good. My bad, didn't realize i had this in the documentation list
I'll dig in more to see what could be causing the issue, and if I find anything I'll get it over to the issues list
Thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants