本文介绍了将响应主体Blob转换为javascript中的json或纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的柏树测试中,我提交了一个请求,并在响应中将正文返回为 blob 。如何检查正文中的一些文本内容。有什么方法可以将 blob 转换为 json或纯文本。请参阅所附的屏幕截图。在下面添加测试代码
In my cypress test, I have submitted a request and in the response the body returned as blob. How can I check the some text content in body. Is there any way convert the blob into json or plain text. Please see the screenshot attached. Adding the test code below
cy.request('someurlHere).then((response) => { expect(response.status).to.eq(200) // this is loooking good expect(response).to.have.property('headers') // this is loooking good console.log(response.text()); //var alertArr = []; //alertArr = response.json(); //console.log(alertArr); })推荐答案
只需检查response.body。请参见以下示例。
Just check for response.body. See below example.
cy .request('POST', 'localhost:8888/users/admin', { name: 'Jane' }) .then((response) => { // response.body is automatically serialized into JSON expect(response.body).to.have.property('name', 'Jane') // true })
更多推荐
将响应主体Blob转换为javascript中的json或纯文本
发布评论