为什么在使用赛普拉斯时需要显式清除会话存储?



我正在使用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。所以我也有点迷茫:)

你试过上下文吗?

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

它存在吗?

最新更新