【问题标题】:Why do I need to explicitly clear sessionStorage when using Cypress?为什么在使用 Cypress 时需要明确清除 sessionStorage?
【发布时间】:2018-06-07 18:00:29
【问题描述】:

我正在使用 Cypress 测试一个 Angular 应用程序,该应用程序通过医生列表进行分页。控制器将当前页面存储在 $sessionStorage.pagination 中。如果我没有明确清除测试之间的会话存储,那么遵循我的“应该转到下一页”测试的测试将失败。如果我明确清除测试之间的会话存储,一切都会按预期工作。这与我在此处阅读的内容 (https://github.com/cypress-io/cypress/issues/686) 相矛盾,这似乎是说会话存储在测试之间会自动清除。

这是 Cypress 中的错误吗?或者,我是否误解了赛普拉斯开发人员在测试之间清除会话存储的意思?

describe('Simple Search Results Page Tests', function () {

    beforeEach(function(){
      cy.server();

    // routes omitted for brevity 

    // Changing pages breaks tests if I visit page under test like this
    cy.visit('http://localhost:9001/pageUnderTest'); 

    // tests work as expected if I visit page under test like this
    /*
    cy.visit('http://localhost:9001/pageUnderTest', 
              {onBeforeLoad: (win) => { win.sessionStorage.clear()}
    });
    /*
  }); 

  it('should search Best Match', function(){
    cy.get('[data-cy=first-name]').first().should('have.text', 'Michael')
      .get('[data-cy=last-name]').first().should('have.text', 'Emiley')
    });

  it('should go to the next page', function(){
    cy.get('[data-cy="page-number"]').click('right')
  }); 

  // this test is broken if session storage not explicitly re-set.
  it('should search Best Match (again)', function(){
    cy.get('[data-cy=first-name]').first().should('have.text', 'Michael')
      .get('[data-cy=last-name]').first().should('have.text', 'Emiley')
    });
});

【问题讨论】:

    标签: angular session-storage cypress


    【解决方案1】:

    open gitlab issue 似乎与您的问题相符,并确认这是一个请求的功能。

    尽管通读this epic is mentioned,它表明赛普拉斯确实清除了sessionStorage。所以我也有点失落:)

    【讨论】:

      【解决方案2】:

      你尝试过上下文吗?

      context('test 1', function () { cy.setCookie('test') })
      context('test 2', function () { cy.getCookie('test').should('not.exist' })
      

      它存在吗?

      【讨论】:

        猜你喜欢
        • 2023-03-25
        • 1970-01-01
        • 2018-01-22
        • 2022-01-05
        • 2014-04-03
        • 2011-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多