Cypress: Assertion on getCookie() is called twice in the Cypress runner

Created on 7 Mar 2020  路  6Comments  路  Source: cypress-io/cypress

Current behavior:

I am asserting cy.getCookie() only once in my code, but the Cypress runner shows the assertion happened twice. Though it is a very minor and low priority issue, it is not the most optimum as the logic for validating the cookie from cypress-runner.js is being called twice and adds to the execution time.

Desired behavior:


Cypress runner should show the ASSERT log only once for cy.getCookie('auth').should('exist')

Test code to reproduce


// cypress/integration/login.spec.js
it('should login successfully with correct credentials and get auth cookie', () => {
    cy.get('#loginForm').within(() => {
      cy.get('#email')
        .clear()
        .type('[email protected]')
        .get('#password')
        .clear()
        .type('Pass1234');
      cy.contains('Login').click();
    });
    cy.title().should('eq', 'Crates for everyone! - Crate');
    cy.url().should('eq', `${Cypress.config().baseUrl}/crates`);
    cy.getCookie('auth').should('exist');
  });

image

Both the ASSERTs print exactly the same message from the same line number of the Cypress runner source code cypress-runner.js:168422 to the DevTools console

image

image

Versions

Cypress:

"devDependencies": {
    "cypress": "^4.1.0"
 }

OS:

ProductName:    Mac OS X
ProductVersion: 10.14.6

Browser:

Google Chrome is up to date
Version 80.0.3987.132 (Official Build) (64-bit)
first-timers-only internal-priority pkdriver regression v4.0.0

Most helpful comment

@jennifer-shehane Thanks for your pointer. I opened a pull request that should fix the described issue. If you have a spare minute please let me know what you think of my proposed solution.

I really enjoyed working with the codebase and hopefully there will be other opportunities for me to contribute in the future!

Have a good Friday! 馃檪

All 6 comments

Yeah...not sure why it's doing that.

This began happening in Cypress 4.0.0. There's a lot of changes in 4.0.0, but my complete guess is maybe it involves the Chai upgrade https://github.com/cypress-io/cypress/pull/2862.

spec.js

it('cookie verification', () => {
  cy.visit('https://example.cypress.io/commands/cookies')
  cy.get('#getCookie .set-a-cookie').click()
  cy.getCookie('token').should('exist')
});

3.8.1

Screen Shot 2020-07-09 at 2 38 02 PM

4.0.0+

Screen Shot 2020-03-09 at 9 27 14 PM

Screen Shot 2020-03-09 at 9 41 14 PM

The below code does not log the assertion twice.

it('cookie verification', () => {
  cy.visit('https://example.cypress.io/commands/cookies')
  cy.get('#getCookie .set-a-cookie').click()
  cy.getCookie('token').then((cookie) => {
    expect(cookie).to.exist
  })
});

HI @jennifer-shehane,

I had a look at this and it looks like the change in https://github.com/cypress-io/cypress/pull/2862 that is causing the assertion to run twice is:

https://github.com/cypress-io/cypress/pull/2862/files#diff-462c090a4a1cf87c581bae15f3af0d6aR111

It looks the same behaviour has been ported from the Coffescript to the Javascript version of asserting.

Example spec

it('cookie verification', () => {
  cy.visit('https://example.cypress.io/commands/cookies')
  cy.get('#getCookie .set-a-cookie').click()
  cy.getCookie('token').should('exist')
});

Running the spec against latest develop

Screen Shot 2020-08-11 at 1 02 48 pm

Running the spec against https://github.com/cypress-io/cypress/pull/8246

Screen Shot 2020-08-11 at 12 57 51 pm

I don't really understand why the code was introduced in the first place but it looks like most checks pass against the draft pull request I opened. Is there anything else you would like me to do or look at before requesting a review for the pull request?

@Tomastomaslol The PR will require tests to ensure that this is no longer logging twice in the UI. There's some idea of what these tests look like around command logs here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/integration/commands/cookies_spec.js#L174:L174

@jennifer-shehane Thanks for your pointer. I opened a pull request that should fix the described issue. If you have a spare minute please let me know what you think of my proposed solution.

I really enjoyed working with the codebase and hopefully there will be other opportunities for me to contribute in the future!

Have a good Friday! 馃檪

The code for this is done in cypress-io/cypress#8276, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 5.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.2.0, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

egucciar picture egucciar  路  3Comments

weskor picture weskor  路  3Comments

stormherz picture stormherz  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments