skip to Main Content

Right now whenever we write a new file that contains Cypress custom commands we add it using
Cypress.Commands.add()
and then import the file in support/index.js.

But my problem here is that I’ve 100 such Custom command files, and I cannot load every file everytime I run cypress, because this is going to cause memory issue soon or after

Instead is there a way to import the cypress custom command files in each testcase spec file itself (if needed) instead of support/index.js?

2

Answers


  1. Chosen as BEST ANSWER

    I just found out that you can import the custom command file in your test script file as well

    I just added

    import './customCommand.js'

    in my test script file and accessed the command as usual like

    cy.customCommand1();

    and it worked fine


  2. You can import the commands individually in the spec where they are used, the syntax is the same as you are already using in support/index.js. I can’t think of any reason why not.

    This would only have an effect if you run the specs individually, obviously.

    But I do not think it will cause much difference to the memory usage, since code files have a small footprint (compared to say fixture files).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search