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

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

Closed
S-Lomax opened this issue Aug 3, 2023 · 18 comments · Fixed by #28428
Assignees

Comments

@S-Lomax
Copy link

S-Lomax commented Aug 3, 2023

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

@nagash77
Copy link
Contributor

nagash77 commented Aug 4, 2023

Hi @S-Lomax, In 12.15 we did do some work around privileged commands. However your example does not give enough context into how you are calling these functions that would cause this problem. In order to give our engineers the best chance at recreating your problem, please create a reproducible example using a fork of Cypress Test Tiny. This gives us the best chance of seeing exactly what you are seeing and being able to investigate effectively.

@nagash77 nagash77 self-assigned this Aug 4, 2023
@S-Lomax
Copy link
Author

S-Lomax commented Aug 7, 2023

Hi @nagash77, thank you for your response. So far we've been unable to reproduce the issue using https://github.com/cypress-io/cypress-test-tiny, even when we change the URL to our own app and use the same code.

We've tried clearing the cypress cache and reinstalling cypress but still hit the same issue every time. Is there any other information we might be able to give you that would help?

@adrienharnay
Copy link

Not sure it is linked to a cache problem, as we are facing the same issue on our CI since upgrading from 12.14.0 to 12.17.3 and we don't have any cache on it. Haven't figured out a way to reproduce it yet either.

@bobilo-qa
Copy link

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

@jbarthe
Copy link

jbarthe commented Aug 9, 2023

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

@nagash77
Copy link
Contributor

nagash77 commented Sep 8, 2023

Hi @jbarthe at a glance that test should work. Are you able to create a reproducible example using a fork of Cypress Test Tiny. This gives us the best chance of seeing exactly what you are seeing and being able to investigate effectively.

@BloodyRain2k
Copy link

BloodyRain2k commented Sep 12, 2023

I've started getting this issue a couple days ago. Completely randomly. Didn't update Cypress or anything.
Been working fine on this SPFX project using Cypress 12.17 for weeks.

And then I've started randomly getting these errors:
Screenshot 2023-09-12 104116

The worst part being that they are literally random...
I can run the exact same test 20 times and 1-2 of those times it might throw it...

It would be really helpful if the error logger would include the invokation origin.
Because as far as I can see, it's always the same: the spec file where the code came from...

I have yet to even find out if that error above about the SP worker might be related.
Edit: ok, seems like that one's not related. Just had a run that was completely fine again, despite the Web Worker constantly throwing errors.

@jennifer-shehane
Copy link
Member

@BloodyRain2k We'd really like to address this issue if it's happening unwarranted to users and randomly.

Can anyone provide a reproducible example? Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue and removed Needs Reproduction labels Oct 5, 2023
@S-Lomax
Copy link
Author

S-Lomax commented Oct 5, 2023

Hi @jennifer-shehane we've been able to reproduce the issue using a fork of but only using our application. We're currently trying to work on a solution where we can provide a successful reproduction to you without giving access to our application.

@newell-paul
Copy link

I have had this problem since attempting to update from 12.8.1 to 13.2.0. This tiny change fixed it in my particular case:

This line works in 12.8.1 and fails in 13.2.0 with the error: "must only be invoked from the spec file or support file."

return cy.task('findDownloadMatching', pattern).then(cy.readFile)

Changing the line to this works in 13.2.0:

return cy.task('findDownloadMatching', pattern).then(filePath => { cy.readFile(filePath) })

@KrzGruszcz
Copy link

@newell-paul I have the same problem: after upgrading Cypress to 13.3.1. getting this error: must only be invoked from the spec file or support file.

I was using cypress v11.2.0 and cy.readFile command like this:

cy.wrap(<some_path>).then(cy.reafFile)

In v13.3.1 I have to change it to this:

cy.wrap(<some_path>).then(path => cy.readFile(path))

@KrzysztofWisniewskiAcc
Copy link

KrzysztofWisniewskiAcc commented Oct 21, 2023

Same problem on version 13.3.2
More data:
#27845 (comment)

mb try to clean cache on your npm ?
I'm experiencing this on all environments, it's kind of strange that this is stated as 'occurs randomly '

@S-Lomax
Copy link
Author

S-Lomax commented Oct 25, 2023

@jennifer-shehane, still working on getting a reproduction using Cypress Test Tiny but one thing we have noticed is that our site uses basic auth and when we bypass basic auth we no longer receive the error.

@S-Lomax
Copy link
Author

S-Lomax commented Oct 31, 2023

Hi @jennifer-shehane / @nagash77 we've managed to reproduce using a fork from the cypress tiny test which can be accessed here:
https://github.com/S-Lomax/cypress-test-tiny

Please let me know if you need any further information.

@S-Lomax
Copy link
Author

S-Lomax commented Dec 4, 2023

@BloodyRain2k We'd really like to address this issue if it's happening unwarranted to users and randomly.

Can anyone provide a reproducible example? Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

@jennifer-shehane / @nagash77 bumping this thread again as we managed to reproduce using a fork from the cypress tiny test which can be accessed here:
https://github.com/S-Lomax/cypress-test-tiny

Looks like the cause of the issue in our case is when basic auth is on the site under test.

Please let me know if you need any further information.

@chrisbreiding
Copy link
Contributor

@S-Lomax Good news! This issue has been fixed by #28428, which will be released in a new version of Cypress this week. Thank you for your patience!

@S-Lomax
Copy link
Author

S-Lomax commented Dec 4, 2023

@S-Lomax Good news! This issue has been fixed by #28428, which will be released in a new version of Cypress this week. Thank you for your patience!

Amazing, thanks for the update.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 5, 2023

Released in 13.6.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.6.1, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet