簡體   English   中英

使用賽普拉斯時,為什么需要顯式清除sessionStorage?

[英]Why do I need to explicitly clear sessionStorage when using Cypress?

我正在使用賽普拉斯(Cypress)測試可在醫生列表中進行分頁的Angular應用程序。 控制器將當前頁面存儲在$ sessionStorage.pagination中。 如果我沒有明確清除測試之間的會話存儲,則遵循“應轉到下一頁”測試的測試將失敗。 如果我確實明確清除測試之間的會話存儲,那么一切都會按預期進行。 這與我在這里閱讀的內容( https://github.com/cypress-io/cypress/issues/686 )矛盾,這似乎表明會話存儲是在測試之間自動清除的。

這是賽普拉斯中的錯誤嗎? 還是我誤解了賽普拉斯開發人員在測試之間清除會話存儲的含義?

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')
    });
});

這個公開的gitlab問題似乎與您的問題相符,並確認它是必需的功能。

盡管sessionStorage 此史詩 ,但它指出賽普拉斯確實清除了sessionStorage 所以我也有點迷路:)

您是否嘗試過上下文?

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

是否存在?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM