question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[sessions] cy.session() was passed an invalid option: log

See original GitHub issue

Current behavior

I have the following code:

Cypress.Commands.add('login', (
  username = Cypress.env('USER_EMAIL'),
  password = Cypress.env('USER_PASSWORD')
) => {
  cy.session([username, password], () => {
    cy.visit('/login')
    cy.get('#email').type(username)
    cy.get('#password').type(password, { log: false })
    cy.contains('button', 'Login').click()
    cy.contains('h1', 'Your Notes').should('be.visible')
  }, { log: false })
})

But it fails with:

cy.session() was passed an invalid option: log
Available options are: validate

Although the docs mention I can pass log as an option, besides validate.

Desired behavior

I should be able to disable cy.session logs, as described in the docs.

Test code to reproduce

// package.json

{
  "name": "cy-session",
  "version": "1.0.0",
  "description": "Sample project to demonstrate the usage of Cypress' experimental feature cy.session().",
  "scripts": {
    "cy": "cypress open",
    "test": "cypress run"
  },
  "keywords": [],
  "author": "Walmyr Filho <wlsf82@gmail.com> (https://walmyr.dev)",
  "license": "MIT",
  "devDependencies": {
    "cypress": "^8.2.0",
    "cypress-iframe": "^1.0.1",
    "faker": "^5.5.3"
  }
}
// cypress.json

{
  "baseUrl": "https://notes-serverless-app.com",
  "chromeWebSecurity": false,
  "experimentalSessionSupport": true,
  "fixturesFolder": false,
  "pluginsFile": false
}
// cypress/support/commands.js

Cypress.Commands.add('login', (
  username = Cypress.env('USER_EMAIL'),
  password = Cypress.env('USER_PASSWORD')
) => {
  cy.session([username, password], () => {
    cy.visit('/login')
    cy.get('#email').type(username)
    cy.get('#password').type(password, { log: false })
    cy.contains('button', 'Login').click()
    cy.contains('h1', 'Your Notes').should('be.visible')
  }, { log: false })
})
// cypress/support/index.js

import 'cypress-iframe'
import './commands'
// cypress/integration/notes.spec.js

describe('Notes App', () => {
  beforeEach(() => cy.login())

  it('CRUDS a note', () => {
    const faker = require('faker')
    const noteDescription = faker.lorem.words(4)

    cy.visit('/notes/new')

    cy.get('#content').type(noteDescription)
    cy.contains('button', 'Create').click()

    cy.contains('h1', 'Your Notes').should('be.visible')
    cy.contains('.list-group-item', noteDescription)
      .should('be.visible')
      .click()

    const updatedNoteDescription = faker.lorem.words(4)

    cy.get('#content')
      .clear()
      .type(updatedNoteDescription)
    cy.contains('button', 'Save').click()

    cy.contains('h1', 'Your Notes').should('be.visible')
    cy.contains('.list-group-item', noteDescription).should('not.exist')
    cy.contains('.list-group-item', updatedNoteDescription)
      .should('be.visible')
      .click()
    cy.contains('button', 'Delete').click()

    cy.contains('h1', 'Your Notes').should('be.visible')
    cy.contains('.list-group-item', updatedNoteDescription).should('not.exist')
  })

  it('successfully submits the settings form', () => {
    cy.intercept('POST', '**/prod/billing').as('paymentRequest')

    cy.visit('/settings')

    cy.get('#storage').type('1')
    cy.get('#name').type('Mary Doe')
    cy.iframe('[title="Secure card payment input frame"]')
      .as('iframe')
      .find('[name="cardnumber"]')
      .type('4242424242424242')
    cy.get('@iframe')
      .find('[name="exp-date"]')
      .type('1222')
    cy.get('@iframe')
      .find('[name="cvc"]')
      .type('123')
    cy.get('@iframe')
      .find('[name="postal"]')
      .type('12345')
    cy.contains('button', 'Purchase').click()

    cy.wait('@paymentRequest').then(response => {
      expect(response.state).to.equal('Complete')
    })
  })

  it('logs out', () => {
    cy.visit('/')

    cy.contains('.navbar-right [href="#"]', 'Logout').click()

    cy.get('#email').should('be.visible')
  })
})

Cypress Version

8.2.0

Other

Note: If I remove the options 3rd argument from cy.session, everything works fine, but then cy.session commands are logged into the Cypress command logs, which is exactly what I want to avoid.

Note 2: I’m using a macOS Big Sur Version 11.5 (20G71)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
wlsf82commented, Mar 24, 2022

Any updates on allowing passing { log: false } to cy.session?

5reactions
kucebcommented, Aug 10, 2021

@wlsf82 we’ll add the log option, but for your use case I suggest not passing password into session id. as long as usernames are unique that will work the same. and that way your demonstration video can still include the session log

Read more comments on GitHub >

github_iconTop Results From Across the Web

session - Cypress Documentation
Because cy.session() clears the page and all session data before running setup , you can use it to easily switch between sessions without...
Read more >
Broken cy.select() after cy.session() (cypress 10.09)
The issue is with pages with <select> elements. After session() was implemented, the cy.select() stopped working. It chose the right option, ...
Read more >
Invalidate cy.session From cypress-data-session - YouTube
dataSession and cy. session and if the data needs to be recomputed, we invalidate all saved Cypress sessions to have the user account...
Read more >
Use cy.session() instead of login page object in Cypress
Creating multiple sessions. Let's say you have multiple users you want to test your UI against. The first argument of cy.session() command is ......
Read more >
How to save and restore state in Cypress tests - Reflect.run
The new cy.session() command solves this problem by caching and restoring cookies, localStorage and sessionStorage after a successful login. The ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found