我可以使用cy.session()而不致电cy.visit()吗?
我是赛普拉斯的新手,如果问题不足,则很抱歉。简短描述我要实现的工作流程:
describe('user selects products and navigates away from page', () => {
//1
it('user logs in and selects products', () => {
})
//2
it('user proceeds to compare selected products'), => {
})
//3
it ('user navigates away from comparison page, then back to comparison'), => {
})
})
这是登录函数的样子:
Cypress.Commands.add("openAndLogin", () => {
cy.session('login', () => {
cy.VisitHomePage()
cy.get('#siteHeaderTopRight').find('button.signin-btn').should('contain.text', 'Sign In').click()
cy.userLogin()
})
})
第一个iT-block运行良好,但是第二次会引发错误t进入用户的产品选择。我也不能在第二块中使用cy.visit()。
因此,我的问题是:如果您在上一页上取决于您的操作的页面之间移动,是否可以使用cy.session()?在这种情况下,我不能在每个IT块中称为cy.visit(),我可以吗?
我在某个地方读到,每个IT块都应该能够独立运行,但是将整个流程放在单个iT块中似乎也不正确。想法?
I'm new to Cypress, so apologies, if the question is inadequate. Short description of the workflow that I'm trying to achieve:
describe('user selects products and navigates away from page', () => {
//1
it('user logs in and selects products', () => {
})
//2
it('user proceeds to compare selected products'), => {
})
//3
it ('user navigates away from comparison page, then back to comparison'), => {
})
})
This is what the login function looks like:
Cypress.Commands.add("openAndLogin", () => {
cy.session('login', () => {
cy.VisitHomePage()
cy.get('#siteHeaderTopRight').find('button.signin-btn').should('contain.text', 'Sign In').click()
cy.userLogin()
})
})
The first it-block runs fine, but the 2nd throws an error because I get stuck at some cy.session related intermittent screen and can't get to the user's product selection. I also can't use cy.visit() in the 2nd block.
So my question here is this: is it possible to use cy.session() if you're moving between pages that are dependent on your actions on the previous page? I can't call cy.visit() in each it-block in this scenario, can I?
I read somewhere that each it-block should be able to run independently, but putting the whole flow in a single it-block somehow doesn't seem right, either. Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您包装在
cy.session()
中的任何内容都会在运行期间缓存。首次在内部完成所有内容并缓存所得的cookie,存储等。
这意味着当您调用
cy.openandlogin()
但是恢复所有缓存的值。关键是,每个测试都应调用
cy.openandlogin()
。尝试在会话代码中添加
console.log()
,它只能显示一次。Anything you wrap in a
cy.session()
is cached for the duration of the run.That means when you call
cy.openAndLogin()
the first time it does all the stuff inside and caches the resulting cookies, storage, etc.The second time you call it, it does not repeat the code, but restores all the cached values.
The key thing is, each test should make a call to
cy.openAndLogin()
.Try adding a
console.log()
inside the session code, it should only show once.是的,您可以使用此功能,Aftereach测试获取您的URL,然后在每个测试中进行CY.Visit(New URL)
Yes, you can use this, afterEach test get your url and then in each test make cy.visit(new url)