cypress: "must only be invoked from the spec file or support file." errors using cy.selectFile() & cy.readFile()

Current behavior

Recently updated to Cypress 12.17.3 from 12.14 and are still getting “must only be invoked from the spec file or support file.” errors when using commands cy.selectFile(), cy.readFile() and cy.task().

Exactly the same behaviour as https://github.com/cypress-io/cypress/issues/27149

Desired behavior

No response

Test code to reproduce

cy.get('[data-cy="QA_Automation_Section_Zip-accordion-button"]').click()
cy.get('[data-cy="thumbnail-button-QA_Automation_Slide_Zip"]').click()
cy.get('[data-cy="upload-container"]').selectFile('cypress/fixtures/QA_Automation_Slide_Deploy.png', {force: true})

Cypress Version

12.17.3

Node version

18.16.1

Operating System

Windows 10.0.19045.3208

Debug Logs

No response

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Hi everyone, i’m still experiencing the same issue too. It was working on cypress 12.14.0 but since not.

Cypress Version

12.17.3

Test code to reproduce:

  it('should upload a document', () => {
    cy.intercept('POST', '/property_documents').as('uploadDocuments');

    cy.getBySel('dataroom-document-title')
      .first()
      .click();

    cy.getBySel('file-item').should('not.exist');

    cy.get('#file-uploader-1')
      .selectFile({
        contents: 'cypress/fixtures/rooms.json',
        fileName: 'file.png',
      }, { force: true });

    cy.wait('@uploadDocuments').then(() => {
      cy.getBySel('file-item').should('exist');
      cy.getBySel('dataroom-document-checked').should('exist');
      cy.getBySel('dataroom-document-unchecked').should('have.length', 21);
    });
  });

Current behavior

image

HI @nagash77 I have the same problem as mentioned above. We updated our cypress from 10 to the newest version and for some reason, this line just stopped working:

uploadDocument() {
    cy.get(this.uploadDocumentsForm()).selectFile('cypress/fixtures/example.pdf', { force: true });
  }

I’m getting the same error: must only be invoked from the spec file or support file