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

cy.selectFile() must only be invoked from the spec file or support file. #29800

Open
gmaggiodev opened this issue Jul 3, 2024 · 1 comment
Open
Labels
stage: needs investigating Someone from Cypress needs to look at this v12.5.0 🐛

Comments

@gmaggiodev
Copy link

gmaggiodev commented Jul 3, 2024

Current behavior

After upgrading to latest version of Cypress, when I try to upload a file using cy.selectFile() I got an error (cy.selectFile() must only be invoked from the spec file or support file.). The same code works with Cypress 11.14.0.

Desired behavior

Should work as version 11.14.0

Test code to reproduce

Using cucumber preprocessor I have this rule that is not wotking anymore:

When('the user upload the file {string}', (fileName: string) => {
    cy.get('tf-uploader input[type="file"]').selectFile(`cypress/files/${fileName}`);
});

Cypress Version

13.13.0

Node version

v18.19.0

Operating System

Windows 11

Debug Logs

at <unknown> (https://<###removed###>/__cypress/runner/cypress_runner.js:114038:70)
    at tryCatcher (https://<### removed ###>/__cypress/runner/cypress_runner.js:1807:23)
    at Promise._settlePromiseFromHandler (https://<### removed ###>/__cypress/runner/cypress_runner.js:1519:31)
    at Promise._settlePromise (https://<### removed ###>/__cypress/runner/cypress_runner.js:1576:18)
    at Promise._settlePromise0 (https://<### removed ###>/__cypress/runner/cypress_runner.js:1621:10)
    at Promise._settlePromises (https://<### removed ###>/__cypress/runner/cypress_runner.js:1697:18)
    at <unknown> (https://<### removed ###>/__cypress/runner/cypress_runner.js:2392:25)
From previous event:
    at Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (https://<### removed ###>/__cypress/runner/cypress_runner.js:3486:19)
    at Promise._then (https://<### removed ###>/__cypress/runner/cypress_runner.js:1239:17)
    at Promise.then (https://<### removed ###>/__cypress/runner/cypress_runner.js:1132:17)
    at next (https://<### removed ###>/__cypress/runner/cypress_runner.js:144081:64)
    at <unknown> (https://<### removed ###>/__cypress/runner/cypress_runner.js:144102:16)
    at tryCatcher (https://<### removed ###>/__cypress/runner/cypress_runner.js:1807:23)
    at Promise._settlePromiseFromHandler (https://<### removed ###>/__cypress/runner/cypress_runner.js:1519:31)
    at Promise._settlePromise (https://<### removed ###>/__cypress/runner/cypress_runner.js:1576:18)
    at Promise._settlePromise0 (https://<### removed ###>/__cypress/runner/cypress_runner.js:1621:10)
    at Promise._settlePromises (https://<### removed ###>/__cypress/runner/cypress_runner.js:1701:18)
    at <unknown> (https://<### removed ###>/__cypress/runner/cypress_runner.js:2392:25)
From Your Spec Code:
    at Context.eval (https://<### removed ###>/__cypress/tests?p=cypress\features\7-provisioning%20tools\Marketplace%20Packages'%20Test\PT0009-Package%20Installation%20Job%20Vacancy%20Report.feature:21076:50)
    at Registry.runStepDefininition (https://<### removed ###>/__cypress/tests?p=cypress\features\7-provisioning%20tools\Marketplace%20Packages'%20Test\PT0009-Package%20Installation%20Job%20Vacancy%20Report.feature:8508:48)
    at Object.fn (https://<### removed ###>/__cypress/tests?p=cypress\features\7-provisioning%20tools\Marketplace%20Packages'%20Test\PT0009-Package%20Installation%20Job%20Vacancy%20Report.feature:15707:43)
    at runStepWithLogGroup (https://<### removed ###>/__cypress/tests?p=cypress\features\7-provisioning%20tools\Marketplace%20Packages'%20Test\PT0009-Package%20Installation%20Job%20Vacancy%20Report.feature:15180:29)
    at Context.eval (https://<### removed ###>/__cypress/tests?p=cypress\features\7-provisioning%20tools\Marketplace%20Packages'%20Test\PT0009-Package%20Installation%20Job%20Vacancy%20Report.feature:15703:62)

Other

No response

@gmaggiodev gmaggiodev changed the title After upgrading to latest version of Cypress, when I try to upload a file using cy.selectFile() I got an error (cy.selectFile() must only be invoked from the spec file or support file.). cy.selectFile() must only be invoked from the spec file or support file. Jul 3, 2024
@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Jul 9, 2024
@sofrlachapelle
Copy link

sofrlachapelle commented Aug 19, 2024

I am also getting this regularly. It's incredibly frustrating as it is preventing me from deploying any automation that includes attachments. This wasn't such a big deal a few versions ago but now it happens frequently, but not every time. This was also happening with cy.task() but I have since converted my task to a custom command to avoid the issue. I can't seem to find a way to resolve the selectFile() problem though. For some reason this isn't as frequent on macOS (M1 MacBook) but happens on Windows constantly. I've gone through many iterations of functions and custom commands to try to resolve the issue. Also tried running it from the spec file directly and from my commands support file. Here is my latest iteration that is still failing at about a 15% rate of failure. The referenced fixture is a JSON object containing the relative paths for 40 images.

cy.fixture("images").then((images) => {
  const keys = Object.keys(images);
  const randomCount = Cypress._.random(3, 5); // Select 3 to 5 images
  const selectedImages = Cypress._.sampleSize(keys, randomCount);
  cy.get("[notes='Upload Images'] ~ input").selectFile(
      selectedImages.map((key) => images[key]),
      { force: true }
  );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this v12.5.0 🐛
Projects
None yet
Development

No branches or pull requests

3 participants