1

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.

Lola Ichingbola
  • 3,035
  • 3
  • 16
  • You'll need to refer to docs to passing it to cy.origin() function. https://docs.cypress.io/api/commands/origin#Dependencies--Sharing-Code – jjhelguero Aug 21 '23 at 17:10

1 Answers1

1

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 for experimentalOriginDependencies

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {

    },
    experimentalOriginDependencies: true, 
  },
})

Then 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

cy.origin('https://example.com', () => {
  Cypress.require('../support/commands')
  assert(cy.attachFile, 'attachFile command is available')
})

This example passes

enter image description here

To see it fail without the Cypress.require(), comment it out

enter image description here


Since cy.origin() is just creating a new instance of the Cypress runner, I would expect eventually the support/commands and support/e2e files will be automatically add, and any library you use will be available inside cy.origin().

Lola Ichingbola
  • 3,035
  • 3
  • 16