Vaibhav Jagdale
Vaibhav Jagdale

Reputation: 242

cy.visit() in before(..) block result in CypressError: Cannot call cy.visit() outside a running test

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

Answers (1)

Evgenii Bazhanov
Evgenii Bazhanov

Reputation: 926

You might want to use the arrow function, try like this

        before(() => {
            cy.visit('https://rahulshettyacademy.com/angularpractice/');
        });

cypress docs

Upvotes: 2

Related Questions