3

My organization is fairly big, we use node and are looking into potentially using Cypress. We have like 100 different projects and each have their own Github repository, but we like to share functions and methods and import them. So my question is, is there a way to do that with Cypress custom commands so that it can be a dependency and you can just import them?

Is it as easy as just adding a Github URL in the dependency?

Zoe
  • 27,060
  • 21
  • 118
  • 148
gotime4
  • 309
  • 1
  • 13

1 Answers1

3

You will have to create a library/package that has all those commands implemented. And then in every project you should install Cypress and then import those commands. For example:

In the library you would have something like this in commands.ts if you're using Typescript or commands.js if you're using JavaScript.

Cypress.Commands.add('take', (testSelector) => {
  return cy.get(`[data-test='${testSelector}']`);
});

Then, in the repo you want to use it you'll have to import it from the library.

In your cypress/support/index file you should add:

import '@organization/library-name/path/to/commands';

Note that the name of the package can depend on how you choose to generate it.

Peter Catalin
  • 1,342
  • 1
  • 14
  • 22