0

is there any way to find the Current running cypress command when it reaches the first time to the cypress config.ts file?

actually, I need to do something based on the command used by a user
example
if the cypress command is executed to run specific test cases
I need to do some operation
if the cypress command has some key in command I need to perform some operation

so is there any way to determine which cypress command the user entered while running the cypress

1 Answer 1

0

No, not directly. The cypress.config.ts file is loaded and executed when Cypress starts, and any configuration values set there will not be available until after the configuration file has been processed.

You can include the operation inside the before \ beforeEach hook of the test spec files. If you need to run it every time (regardless of the test spec used), you can include the before \ beforeEach hook inside the support/index.ts file.

If the operation (sorry you didn't specify) is a non-Cypress command, then you can use cy.task.

Sample code:

before(() => { // run this to generate data for the entire suite
    cy.readFile('cypress/fixtures/data.json');
    cy.task('log', 'This will be output to the terminal');
});
1
  • partially useful answer thank you
    – ksk
    Commented Jan 9, 2023 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.