Search code examples
cypress

is there a way to 2 create multiple command files in cypress


To manage or to have more structures format i would like to create multiple commands files based on different pages i have in the application. would it be really possible to create multiple commands files, if yes how we should? else how we can manage all the page scenarios in one commands file?


Solution

  • In the default cypress/support/index.js file you'll see a line like this:

    import "./commands";
    

    This adds the commands from the cypress/support/commands.js file.

    You can similarly add a cypress/support/someOtherCommands.js file and import it in the cypress/support/index.js file by adding this line:

    import "./someotherCommands";
    

    You can add as many of those as you want, you could also nest them in directories for better structure. Example: cypress/support/settings/mainSettingsPage.js would be imported with:

    import "./settings/mainSettingsPage";