试图集成UI和API测试用例
创建了两个文件:
API测试->做登录并写入令牌并将其保存到Fixture文件中
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)
})
});
一旦执行了以上测试,就会重定向到第一个测试。不再进行进一步的测试
您在.then
回调中使用了错误的语法:您的情况下response.body
应该为response.response.body
。