When I use the cypress-file-upload plugin without the cy.origin() function, it works perfectly. However, when I introduce cy.origin() in my test, I get the error cy.get(...).attachFile is not a function, even though I've properly installed and imported the cypress-file-upload plugin in the commands.js file.
What I've tried: Installed cypress-file-upload via npm. Imported it in my cypress/support/commands.js file with import 'cypress-file-upload';. Used the .attachFile() method without cy.origin() and it works perfectly.
The origin command is still a bit new and evolving, but it does have an experimental switch that allows you to use
cypress-file-upload.First, in
cypress.config.js, add the flag forexperimentalOriginDependenciesThen follow the example for internal custom commands given here cy.origin with Custom commands since the cypress-file-upload lib is just another custom command.
A simple example
This example passes
To see it fail without the
Cypress.require(), comment it outSince
cy.origin()is just creating a new instance of the Cypress runner, I would expect eventually thesupport/commandsandsupport/e2efiles will be automatically add, and any library you use will be available inside cy.origin().