如何存储JSON响应主体的特定数据集?

问题描述 投票:0回答:0
现在,我只能通过对其进行过滤,从而使结果仅显示1个数据集。

let id = 2; let userId, title, body; cy.request({ method: "GET", url: "https://jsonplaceholder.typicode.com/posts/", qs: { id: id } }) .then((response) => { expect(response.status).to.eq(200) userId = response.body[0].userId id = response.body[0].id title = response.body[0].title body = response.body[0].body cy.log(`userId: ${userId}, id: ${id}, title: ${title}, body: ${body}`) })

	

let body = JSON.parse(response.body); let userId = body[0].userId;

	
javascript cypress web-api-testing
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.