如何以编程方式登录Cypress for PHP会话网站

如何以编程方式登录Cypress for PHP会话网站,php,authentication,cypress,x-xsrf-token,laravel-session,Php,Authentication,Cypress,X Xsrf Token,Laravel Session,我正在用Cypress编写测试代码。 UI登录已经过测试,没有问题,但是为了测试网站的其他部分,我想以编程方式登录以进行快速测试。 该网站是用PHP编写的,在标题集cookie中使用laravel会话,下面是我的代码: 规格ts it('strategy #2: parse token from response headers', function () { // if we embed our csrf-token in response headers //

我正在用Cypress编写测试代码。 UI登录已经过测试,没有问题,但是为了测试网站的其他部分,我想以编程方式登录以进行快速测试。 该网站是用PHP编写的,在标题集cookie中使用laravel会话,下面是我的代码:

规格ts

it('strategy #2: parse token from response headers', function () {
        // if we embed our csrf-token in response headers
        // it makes it much easier for us to pluck it out
        // without having to dig into the resulting HTML
        cy.request('/auth/login')
        .its('headers')
        .then((headers) => {
          const laravel_session = headers['laravel_session']
    
          cy.loginByCSRF(laravel_session)
          .then((resp: any) => {
            expect(resp.status).to.eq(200)
            expect(resp.body).to.include('<span class="menu-item">Dashboard</span>')
          })
        })
    
        // Set viewport to 1366px x 1024px
        cy.viewport(1366, 1024)
索引d.ts

declare namespace Cypress {
    interface Chainable {

        loginByCSRF: typeof loginByCSRF
    }
}

function loginByCSRF(laravel_session) {
    return this.headers
}
感谢您的帮助。谢谢

declare namespace Cypress {
    interface Chainable {

        loginByCSRF: typeof loginByCSRF
    }
}

function loginByCSRF(laravel_session) {
    return this.headers
}