Skip to main content

Cypress log Command

If a message needs to be printed for our reference in the command log of cypress, then the log command is used.

Syntax

cy.log(message)
cy.log(message, args...)

Arguments used in log command

Message:

  • Used to print the message needed to cypress command log.
  • This accepts a markdown formatted message.

Args:

  • Additional arguments are to be printed in the log.
  • Many arguments can be used here, and there is no limit.

Cypress Log Correct Use:

cy.log('Clone Jutsu')

This will print the string 'Clone Jutsu'

  • cy.log() yields null when used.
  • It cannot be chained further with any other command.
  • It can only be chained off with the cy.
  • It cannot have any assertions chained.
  • The log cannot timeout.

Example

Let us see a sample example of arguments mentioned in action:

Message:

cy.visit('https://www.programsbuzz.com')
cy.log('visit successful')

Prints the message 'visit successful' in the cypress command log.

Args:

cy.log('hokages', ['Minato', 'Saru', 'Naruto'])
  • Prints with the arguments and the message.

Let us see a simple realtime log use example:

describe('Automate AutoPract',()=>{
    it('Should load the url',()=>{
        cy.visit('http://www.autopract.com/#/home/fashion')
        cy.log('Website Visited Successfully')
        
    })
    it('Should close POPUP',()=>{
        cy.get('.close').click()
        cy.log('Popup Closed')

    })
    it('Should click Side bar and get last item text',()=>{
        cy.get('.bar-style').click()
        cy.get('#sub-menu').find('li').last().then($log => {
            const fLog = $log.text()
            cy.log(fLog)
        })

    })
})
  • Here we used logs to print a message and print an object having a text.
  • We extracted the text from an element and stored it in a variable fLog.
  • And we logged the fLog.

Tags
Submitted by arilio666 on February 10, 2022

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.