sai
sai

Reputation: 27

Reference Error :cy is not defined while running cypress test

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)

Upvotes: 3

Views: 12969

Answers (3)

Joshua Dyck
Joshua Dyck

Reputation: 2173

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"
  ]
}

Upvotes: 6

sai
sai

Reputation: 27

The issue was related to eslint Had to install few packages and made an update to eslintrc files

Upvotes: -2

Serhii
Serhii

Reputation: 16

Testing locally, this should work for you. Change path of your json file, and use your custom command cy.login. In my example I just printed variables to console.

describe('The Login', () => {
  beforeEach(() => {
      cy.readFile('cypress/integration/test/test.json').as("user")});
  it("Login", () => {
      cy.get("@user").then((user) =>
      cy.log(user.username, user.pass))
    })
  })

My test.json was:

{
  "username":"[email protected]",
  "pass":"pass"
}

Upvotes: 0

Related Questions