代码之家  ›  专栏  ›  技术社区  ›  soccerway

正在验证cookie cypress抛出的TypeError:环链不是函数

  •  0
  • soccerway  · 技术社区  · 6 年前

    显然是在 '../support/index.js' 有人能告诉我为什么会出现错误吗

    import './commands'
    

    柏树试验:

    describe("Login test validate cookie", () => {
        it.only('Verify the cookies test for login', function() {
            cy
            .login(Cypress.env('email'), Cypress.env('password'))
            cy
            .getCookie('csrftoken')
            .then((csrftoken) => {
                console.log(csrftoken)
            })
        })
    

    Cypress.Commands.add('login', (email, password) => {
        return cy.chain().request({
            method: 'POST',
            form: true,
            url: '${cypress.env("test_server")}',
            body: '{"email", "password"}',
        })
    }); 
    

    以下详情见cypress.env.json文件'文件

    { 
      "email": "test@soccer.nl",
      "password": "test1234"
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Joshua Wade Abel    6 年前

    错误是正确的; cy.chain() 确实不是一个函数。但是,您的命令中有许多问题:

    1. 除非你计划关闭这个命令,否则你不需要返回任何东西。不过,这肯定不会造成任何伤害。
    2. 如前所述, .chain()
    3. 你的 url 字段需要为 ${...} 去工作。
    4. 你的 body 字段将包含“email”和“password”,而不是实际的email和password。

    Cypress.Commands.add('login', (email, password) => {
        cy.request({
            method: 'POST',
            form: true,
            url: `${cypress.env("test_server")}`,
            body: `{"${email}", "${password}"}`,
        });
    });