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
- cy.session log option doesn't actually exist https://github.com/cypress-io/cypress/issues/17642 — committed to lol768/cypress-documentation by lol768 3 years ago
Any updates on allowing passing
{ log: false }tocy.session?Hi @jennifer-shehane 👋🏻
I don’t think that will be needed. By reading the second paragraph of the session caching section of
cy.sessiondocs, I realized this seems to be the expected behavior.Sure, to me, it’s crucial to hide the command logs of
cy.sessionbecause I create videos demonstrating the usage of many Cypress functionalities. If I use[username, password]as my sessionid, I don’t want such information to leak.@wlsf82 we’ll add the log option, but for your use case I suggest not passing
passwordinto session id. as long as usernames are unique that will work the same. and that way your demonstration video can still include the session logAs far as the documentation describes, this issue is still valid since it’s still not possible to pass
log: falseto the options third argument of thecy.sessionfunction.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