Cypress 10 : How to define custom command as global and use in seperate test files #23134
Unanswered
vahidsa
asked this question in
Component Testing
Replies: 1 comment
-
You can create a function in your function.ts file that is being exported (I called it addCommands()). Inside that function, call the Cypress.Comands.addAll({}) method to add all of your custom commands. Then, inside each test you make you just have to import the addComands() function from your function.ts file and call it at the start of each test. This works for me, but the only issue I have is that vs code underlines my custom commands in red even though they work when running the test |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to implement some custom commands in Cypress 10.3 that can be used as global in different test cases or in other words in different files.
I created a functions.ts file in the support folder and defined a custom command there and have been imported it into the e2e.ts file But when I want to use the function in another file, I get an error saying
TypeError cy.getBodyis not a function
I also tried to define the function into interface but I'dont know how can I to implement the function to be used as a global command.
commands.ts:
here is tsconfig.json
Beta Was this translation helpful? Give feedback.
All reactions