Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Error :cy is not defined while running cypress test

Tags:

cypress

Describe('The Login', function () {
    beforeEach(function () {
        cy.readFile(Cypress.env('test')).as("user")});

    it("Login", () => {
        cy.get("@user").then((user) =>
        cy.login(user.username, user.password))})

FAIL cypress/integration/login.spec.js ● The Login Page ›

ReferenceError: cy is not defined

  at Object.<anonymous> (cypress/integration/login.spec.js:4:5)
      at new Promise (<anonymous>)
      at <anonymous>
  at process._tickCallback (internal/process/next_tick.js:188:7)
like image 464
sai Avatar asked Feb 28 '26 07:02

sai


1 Answers

To add some context to the answer by @sai, to resolve this eslint error all I had to do was install eslint-plugin-cypress from here.

npm install eslint-plugin-cypress --save-dev

Then, in my eslint config I added one line to my extends array.

Your config could be .eslintrc.json or the "eslintConfig" configuration object in your package.json

{
  "extends": [
    "plugin:cypress/recommended"
  ]
}
like image 180
Joshua Dyck Avatar answered Mar 02 '26 14:03

Joshua Dyck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!