柏树测试期间未清除本地存储

发布于 2025-02-14 01:09:12 字数 850 浏览 1 评论 0原文

作为我的柏树测试的一部分,我正在尝试登录应用程序。

问题是,当我第二次进行测试时,由于先前的测试,我已经登录了,因此我没有带到登录页面&登录测试失败。

下面是我运行测试时的存储空间:

”

我假设此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:

storageTab

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡风轻 2025-02-21 01:09:12

有一些会话存储,您没有清除。

最简单的方法是

before(() => {
    cy.clearLocalStorage('bluelibs-token')
    cy.clearLocalStorage()
    cy.clearCookies()
})

beforeEach(() => {
    cy.visit('/', {onBeforeLoad: (win) => { win.sessionStorage.clear()})
})

在这里讨论一个空旷的问题在测试之间的清晰sessionstorage#413

目前,我们清除了cookie和localstorage

需要添加这一点,我们可能需要添加一个新的cy.clearsessionstorage api命令。

在本日志的底部,提到了实验cy.session()命令,并暗示稍后版本的cypress(> = v8.2.0)现在将清除会话数据。

但是,由于它是实验性的,因此可能是清除序列需要进行一些调整 - 即,也许它可以清除测试之间的会话存储,而不是在运行后。

There is some Session Storage that you're not clearing.

The simplest way would be

before(() => {
    cy.clearLocalStorage('bluelibs-token')
    cy.clearLocalStorage()
    cy.clearCookies()
})

beforeEach(() => {
    cy.visit('/', {onBeforeLoad: (win) => { win.sessionStorage.clear()})
})

There's an open issue discussing here Clear sessionStorage in between tests #413

Currently we clear cookies and localStorage but somehow we missed automatically clearing sessionStorage as well.

This needs to be added, and we likely need to add a new cy.clearSessionStorage API command.

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.

半暖夏伤 2025-02-21 01:09:12

在函数之前,您无需在中制作这些东西。

如果您需要登录,则可能是您的代码(某些伪伪码:D):

before(() => {
// visit sign in page
// fill form and submit
// the cookies & tokens are stored automatically
})

beforeEach(() => {
    cy.visit('/')
})

it('First Test Case', () => {
// here, because we have "beforeEach" set to '/' => we are on home page already (no need to sign in)
// do wat you want, eg:
    // got to another page
    // select an element etc.
})

// after that, we can write another test, and another, without signing in again

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 ):

before(() => {
// visit sign in page
// fill form and submit
// the cookies & tokens are stored automatically
})

beforeEach(() => {
    cy.visit('/')
})

it('First Test Case', () => {
// here, because we have "beforeEach" set to '/' => we are on home page already (no need to sign in)
// do wat you want, eg:
    // got to another page
    // select an element etc.
})

// after that, we can write another test, and another, without signing in again
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文