3
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)
2
  • 1
    You need to put in more details like code to reproduce, error from the console. Commented Oct 25, 2019 at 6:29
  • added the details Commented Oct 25, 2019 at 16:48

3 Answers 3

6

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"
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

-2

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

2 Comments

I have the same issue. Which packages did you install and what did you update in the eslintrc file?
See my answer for more details @Arek stackoverflow.com/a/60131233/2684661

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.