[英]Why do I need to explicitly clear sessionStorage when using Cypress?
I am using Cypress to test an Angular application that pages through a list of doctors. 我正在使用赛普拉斯(Cypress)测试可在医生列表中进行分页的Angular应用程序。 The controller stores the current page in $sessionStorage.pagination.
控制器将当前页面存储在$ sessionStorage.pagination中。 If I don't explicitly clear the session storage between tests, tests that follow my "should go to next page" test fail.
如果我没有明确清除测试之间的会话存储,则遵循“应转到下一页”测试的测试将失败。 If I do explicitly clear the session storage between tests, everything works as expected.
如果我确实明确清除测试之间的会话存储,那么一切都会按预期进行。 This contradicts what I read here ( https://github.com/cypress-io/cypress/issues/686 ) which seems to say that the session storage is automatically cleared between tests.
这与我在这里阅读的内容( https://github.com/cypress-io/cypress/issues/686 )矛盾,这似乎表明会话存储是在测试之间自动清除的。
Is this a bug in Cypress? 这是赛普拉斯中的错误吗? Or, am I misunderstanding what the Cypress developers mean by clearing session storage between tests?
还是我误解了赛普拉斯开发人员在测试之间清除会话存储的含义?
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')
});
});
This open gitlab issue seems to match your issue and confirms it's a requested feature. 这个公开的gitlab问题似乎与您的问题相符,并确认它是必需的功能。
Reading through though, this epic is mentioned , which states that Cypress does clear sessionStorage
. 尽管
sessionStorage
此史诗 ,但它指出赛普拉斯确实清除了sessionStorage
。 So I'm a bit lost as well :) 所以我也有点迷路:)
Have you tried with context? 您是否尝试过上下文?
context('test 1', function () { cy.setCookie('test') })
context('test 2', function () { cy.getCookie('test').should('not.exist' })
does it exist? 是否存在?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.