![](/img/trans.png)
[英]Trying to get cypress react unit testing working within a ReactBoilerplate repo
[英]I am trying to preserve the Session cookie through multiple tests in cypress but Cypress.Cookie.preserveOnce() is not working
我实现这个功能是错误的还是我错过了什么? 我查看了开发人员工具的应用程序选项卡,cookie 出现在 setToken() 方法之后,但尽管 Cypress.Cookies.preserveOnce('token_name') 在每个钩子之前。 令牌仍然在测试之间被擦除。
before(() => {
cy.setToken()
})
beforeEach(() => {
Cypress.Cookies.preserveOnce("token_name")
cy.visit(urlPrefix + 'applications').wait(beforeEachWait)
})
after(() => {
cy.clearCookies()
})
it('Form should have title', () => {
cy.contains('Edit Application').should('be.visible')
})
it('The Save button should be disabled until changes have been made', () => {
cy.get('[data-cy=saveBtn]').should('be.disabled')
cy.get('[data-cy=applicationName] input').type(' edited')
cy.get('[data-cy=saveBtn]').should('be.enabled')
})
it('The cancel button redirects to the list view', () => {
cy.get('[data-cy=cancelBtn]')
.click()
.wait(500)
cy.url().then(url => {
const applicationsTitle = url.split('#/')[1]
expect(applicationsTitle).to.equal('applications')
})
})
it('should have delete button in edit mode', () => {
cy.get('[data-cy=deleteBtn]').should('be.visible')
})
})
cypress 最新版本 10.8.0 无需添加 setCookie。 在 cypress.config.ts 文件中添加 expermentalSessionAndOrigin 和 chromeWebSecurity
e2e: {
baseUrl: "xxxxxxxxxxxxxxxxxxx",
experimentalSessionAndOrigin: true,
chromeWebSecurity: false,
}
用这个
Cypress.Cookies.defaults({
preserve: 'session_id',
})
它会工作或
before("cookies",() => {
cy.setCookie('session_name', 'value')
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.