Elshaikh
Elshaikh

Reputation: 41

Executing a spec before and after the main spec by cypress

I need to execute header.spec.js after and before I ran the main tests. To ensure all passed

I am looking for something like this:

before(function () {
  // I want here to call header.spec.js
});

it(`check the work flow`, () => {
  // this is the main spec that will page context 
})

after(function () {
  // I want here to call footer.spec.js
});

Upvotes: 0

Views: 541

Answers (1)

DurkoMatko
DurkoMatko

Reputation: 5834

If I understand correctly, your header.spec.js and footer.spec.js are scripts which you want to just execute? They don't contain any tests? You're using before and after Hooks correctly. To execute a Javascript file within these hooks, you can use cy.exec() command which is described here. E.g. with Node.js, you'd run those files like this (assuming their in the same directory):

cy.exec("node header.spec.js");

Hope I understood your situation correctly.

Upvotes: 1

Related Questions