Search code examples
javascriptcypresstest-suite

How to call a test suite from another test case in Cypress?


The application I am working on requires me to call multiple test suites in the current testcase. I know that we can add the resuable command in suport/commands.js but that is not I am looking for.

testsuiteA.js

  describe(This should be called in another, function({
   .....
   })
  it(TestCase1,function(){....})
  it(TestCase2,function(){....})

I want to call the entire testSuiteA in a new testsuiteB or sometimes want to call only specific test cases of that suite. I tried some ways but I am stuck now.


Solution

  • Since the describe() and it() blocks are JavaScript functions, you can create a function that calls them and export that function.

    // foo.js
    export myTests function() {
      describe('Reusable tests', function () {
        // test content here
      });
    }
    
    // test-file.js
    import { myTests } from "./foo.js" // import the function
    
    myTests(); // run the tests