Reputation: 242
I am writing spec file for Cypress. I have one spec file including 3-4 tests. each test using the same url so instead of writing cy.visit in each test, I am trying to move in before(..) block.
before(){
cy.visit('https://rahulshettyacademy.com/angularpractice/');
}
but I am getting CypressError: Cannot call cy.visit() outside a running test. How can use cy.visit in before(..) block?
Upvotes: 2
Views: 1419
Reputation: 926
You might want to use the arrow function, try like this
before(() => {
cy.visit('https://rahulshettyacademy.com/angularpractice/');
});
cypress docs
Upvotes: 2