Erenn
Erenn

Reputation: 683

Show test body, test steps for passing tests in Cypress

When tests pass in Cypress it doesn't show the steps but if fails it shows all the steps and what step caused test to fail.

I want to see passing tests body/steps too.

Below image shows a passing test and a failing test. Failing test is much more informative. I want passing test to be like that too. How can I achieve this?

enter image description here

 it('should select shipment method and type "test" into additional 
   notes', function () {
     cy.intercept('GET', 
  '**/GetDetailWithAvailableCampaign*').as('basketDetails')
  
  cy.on('uncaught:exception', (err, runnable) => { // If CheckoutJS throws an error, it will be caught here
    cy.get('[data-cy="information::forward"]').click()
    cy.url().should('include', '/basket/checkout/payment')
  
    cy.get('[data-cy="shipping::shipment_type"]').first().click()
    cy.get('[data-cy="shipping::shipment_type"]').should('be.checked')
  
    cy.get('[data-cy="misc::additional_message_checkbox"]').check({force: true}).should('be.checked')
    cy.get('[data-cy="misc::additional_message_textarea"]').should('be.visible').clear().type('Test')
  
    // there is no shipping::forward
    // cy.get('[data-cy="shipping::forward"]').click()
  
    cy.get('[data-cy="information::forward"]').click()
  })
})

it('should focus iframe and put a credit card', function () {
    cy.wait(4000)
    cy.url().should('include', '/basket/checkout/shipping')
    const iframeSelector = 'iframe[data-cy="payment::iframe"]'
    getIframeBody(iframeSelector).find('.btn-card-visa').click()
    cy.wait(2000)
    getIframeBody(iframeSelector).find('input#CardNumber').clear().type(Cypress.env('credit_card').number)
    getIframeBody(iframeSelector).find('input#Expiry').clear().type(Cypress.env('credit_card').expiry)
    getIframeBody(iframeSelector).find('input#HolderName').clear().type(Cypress.env('credit_card').holder_name)
    getIframeBody(iframeSelector).find('input#VerificationCode').clear().type(Cypress.env('credit_card').cvv)

    getIframeBody(iframeSelector).find('.btn-next').click()
}

Upvotes: 2

Views: 428

Answers (1)

agoff
agoff

Reputation: 7135

By default, clicking on a test's name in the runner will expand and show all steps executed. In your case, it is doing this. But the issue you are running into is most likely that the uncaught:exception event you are waiting for in the first test is not occurring, and therefore no steps are executed. If you remove the cy.on('uncaught:exception'), you'll see the steps are executed.

Upvotes: 4

Related Questions