jeudi 17 octobre 2019

I am trying to preserve the Session cookie through multiple tests in cypress but Cypress.Cookie.preserveOnce() is not working

Am I implementing this functionality wrong or am i missing something?? I watch the application tab of the developer tools, the cookie appears after the setToken() method but despite the Cypress.Cookies.preserveOnce('token_name') in the before each hook. The token is still erased in between tests.

  before(() => {
    cy.setToken()
  })

  beforeEach(() => {
    Cypress.Cookies.preserveOnce("token_name")
    cy.visit(urlPrefix + 'applications').wait(beforeEachWait)
  })

  after(() => {
    cy.clearCookies()
  })

  it('Form should have title', () => {
    cy.contains('Edit Application').should('be.visible')
  })

  it('The Save button should be disabled until changes have been made', () => {
    cy.get('[data-cy=saveBtn]').should('be.disabled')
    cy.get('[data-cy=applicationName] input').type(' edited')
    cy.get('[data-cy=saveBtn]').should('be.enabled')
  })

  it('The cancel button redirects to the list view', () => {
    cy.get('[data-cy=cancelBtn]')
      .click()
      .wait(500)

    cy.url().then(url => {
      const applicationsTitle = url.split('#/')[1]
      expect(applicationsTitle).to.equal('applications')
    })
  })

  it('should have delete button in edit mode', () => {
    cy.get('[data-cy=deleteBtn]').should('be.visible')
  })
})

Aucun commentaire:

Enregistrer un commentaire