
如果想从头学起Cypress,可以看下面的系列文章哦
https://www.cnblogs.com/poloyy/category/1768839.html
清除指定名称的 Cookie
cy.clearCookie(name)
cy.clearCookie(name, options)name 必传
// 清除 token 这个 Cookie
cy.clearCookie('token')describe('clearCookie() 命令详解', function () {
beforeEach(() => {
cy.visit('https://example.cypress.io/commands/cookies')
})
it('栗子一', () => {
// 执行测试用例, 暂无 Cookie
cy.getCookie('token')
.should('be.null')
// 获取 Cookie
cy.get('#clearCookie .set-a-cookie').click()
cy.getCookie('token')
.should('have.property', 'value', '123ABC')
// 清除 Cookie
cy.clearCookie('token')
cy.getCookie('token')
.should('be.null')
})
it('栗子二', () => {
// 测试用例之间 Cookie 不会共享
cy.getCookie('token')
.should('be.null')
})
})可以使用 .should('be.null') 判断某 Cookie 是空的

