
如果想从头学起Cypress,可以看下面的系列文章哦
https://www.cnblogs.com/poloyy/category/1768839.html
获取指定名称的 Cookie
cy.getCookie(name)
cy.getCookie(name, options)name 必传
// 获取 token 这个 Cookie
cy.getCookie('token')返回一个 Cookie 对象,并且包含以下属性
注意:当找不到指定 Cookie 时,该命令会返回 null

.should(exist)
.should('have.property')
.then()


一个 cookie 对象一定会包含上面的六个属性
//<reference types="cypress" /R>
describe('getCookie 登录页面', function () {
const username = 'jane.lane'
const password = 'password123'
before(function () {
// 登录操作
cy.visit("http://localhost:7079/login")
cy.get("input[name=username]").type(username)
cy.get("input[name=password]").type(password)
cy.get("form").submit()
})
it('获取登录后的 cookie', function () {
cy.getCookie("cypress-session-cookie")
.should('exist')
.should('have.property', 'domain', "localhost")
.then((cookies) => {
cy.log(cookies)
})
})
})