cy.request不允许我进入下一个UI测试用例

问题描述 投票:0回答:1

试图集成UI和API测试用例

创建了两个文件:

  1. API测试->做登录并写入令牌并将其保存到Fixture文件中

  2. Spec test->使用用户名和密码进行真实登录,一旦通过测试用例,然后在下一个测试中首先使用cy.request使用由step1保存的令牌获得响应。根据响应键在搜索栏中搜索数据

API测试文件:

it("Login Request API",function(){

        cy.request({
            method:"POST",
            url: POST URL,
            headers:{
             "content-type" : "application/json"
            },
            body : {
             "email": USER NAME,
             "password": PASSWORD
            },
            log: true
        }).then((response) => {
             // Parse JSON the body.
             expect(response.status).to.equal(200)
             let resbody = JSON.parse(JSON.stringify(response.body));
            cy.writeFile("File Path to store response",resbody)
         })
    });

一旦执行了以上测试,就会重定向到第一个测试。不再进行进一步的测试

javascript mocha cypress
1个回答
0
投票

您在.then回调中使用了错误的语法:您的情况下response.body应该为response.response.body

© www.soinside.com 2019 - 2024. All rights reserved.