柏树测试期间未清除本地存储
作为我的柏树测试的一部分,我正在尝试登录应用程序。
问题是,当我第二次进行测试时,由于先前的测试,我已经登录了,因此我没有带到登录页面&登录测试失败。
下面是我运行测试时的存储空间:
我假设此bluelibs-token
价值是我已经登录的原因。
我试图在测试运行之前清除存储/cookie,但我仍然登录。
下面是我的测试代码:
before(() => {
cy.clearLocalStorage('bluelibs-token')
cy.clearLocalStorage()
cy.clearCookies()
})
beforeEach(() => {
cy.visit('/')
})
it('First Test Case', () => {
cy.contains('Sign In').click();
// this fails as I am brought to the user's account rather than the sign-in page (I would be brought to the sign-in page if I wasn't logged in)
})
有人可以指出为什么这个令牌不是清除,&我如何在每个测试中登录?
As part of my Cypress test, I am trying to log into an application.
The problem is that when I run the test a second time, I am already logged in, due to the previous test, so I'm not brought to the sign-in page & the login test fails.
Below is the storage when I run the test:
I assume this bluelibs-token
value is the reason I'm already logged in.
I have tried to clear the storage/cookies before the test run, but I'm still logged in.
Below is my test code:
before(() => {
cy.clearLocalStorage('bluelibs-token')
cy.clearLocalStorage()
cy.clearCookies()
})
beforeEach(() => {
cy.visit('/')
})
it('First Test Case', () => {
cy.contains('Sign In').click();
// this fails as I am brought to the user's account rather than the sign-in page (I would be brought to the sign-in page if I wasn't logged in)
})
Can someone please point out why this token is not being cleared, & how I can log in during each test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一些会话存储,您没有清除。
最简单的方法是
在这里讨论一个空旷的问题在测试之间的清晰sessionstorage#413
在本日志的底部,提到了实验
cy.session()
命令,并暗示稍后版本的cypress(> = v8.2.0)现在将清除会话数据。但是,由于它是实验性的,因此可能是清除序列需要进行一些调整 - 即,也许它可以清除测试之间的会话存储,而不是在运行后。
There is some Session Storage that you're not clearing.
The simplest way would be
There's an open issue discussing here Clear sessionStorage in between tests #413
Toward the bottom of this log the experimental
cy.session()
command is mentioned and implies that later versions of Cypress (>= v8.2.0) will now clear session data.But since it's experimental, it may be the clearing sequence needs some adjustment - i.e maybe it clears Session Storage between tests but not after runs.
在函数之前,您无需在
中制作这些东西。
如果您需要登录,则可能是您的代码(某些伪伪码:D):
You do not need to make these things in
before
function.If you need to sign in, then your code may be (some pseudo-pseudocode :D ):