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

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)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 8
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

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

Hi @jennifer-shehane 👋🏻

@wlsf82 Can you open a new issue demonstrating and describing this second issue?

I don’t think that will be needed. By reading the second paragraph of the session caching section of cy.session docs, I realized this seems to be the expected behavior.

It does appear that cy.session should take a log option as indicated from the docs, but I don’t see this actually being an option that was coded as part of sessions, so I think the docs are incorrect.

You want to be able to hide the cy.session entry in the Command Log? Can I ask why you want to do this? Just want some context although it seems reasonable since most of the other commands have this option.

Sure, to me, it’s crucial to hide the command logs of cy.session because I create videos demonstrating the usage of many Cypress functionalities. If I use [username, password] as my session id, I don’t want such information to leak.

@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

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

As far as the documentation describes, this issue is still valid since it’s still not possible to pass log: false to the options third argument of the cy.session function.

So please, keep it opened and address it. 🙏🏻

@wlsf82 Thanks for the explanation - this is a great reason. I agree.

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

Hi. Is there any word on this? Having log:false would be a great addition. @jennifer-shehane