angular - 为什么在使用 Cypress 时需要明确清除 sessionStorage?
问题描述
我正在使用赛普拉斯测试一个通过医生列表分页的 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
。所以我也有点失落:)
推荐阅读
- networking - 不懂 minecraft 数据包
- numpy - 错误缓冲区对于请求的数组来说太小
- azure - 使用 azure api 确定 azure 订阅中资源的价格
- android - 无法使用指南删除边距
- redis - Celery - 自动重试在崩溃的工作人员上运行的长时间运行的任务
- python - 电报机器人在命令 Python 后等待用户回复
- html - 矩形边框的CSS形状半圆对齐问题
- android - 请求 Google 驱动器范围权限时会提供无限加载对话框
- windows - 在支持 GPU 的 Windows 10 上部署 TF2 模型
- html - HTML 实体在页面刷新时未呈现正确的字符