是否可以在柏树测试中通过循环发送网络请求
我知道,通过赛普拉斯的环路发送网络请求也有同样的官方限制, 但是可能有一些非正式的方法可以做到这一点。
用例是发送一些cy.request()
,并包装在中in()
或while while()
loop并传递不同的值每次从某个数组或直接从数据库中的标头开始,然后通过某种断言对结果进行操作。
例如
let query = 'query bla bla bla'
let projectId = some value from array or db';
let result;
describe('Tests', () => {
it('send graphql request to endpoint', () => {
for(let i = 0; 0 > 3; i++) {
cy.request({
method: 'POST',
url: 'https://www.blabla.con/api2',
body: {
'operationName': 'bla bla',
'variables': {
'campaignProjectId': null,
'ids': [ { 'type': 'project', 'id': projectId } ],
'userData': null,
},
query,
},
headers: {
'accept': '*/*',
'content-type': 'application/json',
},
}).then((response: any) => {
// placeholder for assert - will compare between the results
expect(JSON.stringify(response.body.data).is.equal(JSON.stringify(result);
});
};
});
,在上面的代码中,它只是循环而无需发送请求,似乎是递归问题或其他问题。
I know there is same official limitation to send network request by loop in Cypress,
but probably there is some unofficial way to do it.
The use case is to send some cy.request()
and wrap in in for()
or while()
loop and pass different values in the header everytime from some array or directly from the database and then to manipulate on the result by some assert.
e.g.
let query = 'query bla bla bla'
let projectId = some value from array or db';
let result;
describe('Tests', () => {
it('send graphql request to endpoint', () => {
for(let i = 0; 0 > 3; i++) {
cy.request({
method: 'POST',
url: 'https://www.blabla.con/api2',
body: {
'operationName': 'bla bla',
'variables': {
'campaignProjectId': null,
'ids': [ { 'type': 'project', 'id': projectId } ],
'userData': null,
},
query,
},
headers: {
'accept': '*/*',
'content-type': 'application/json',
},
}).then((response: any) => {
// placeholder for assert - will compare between the results
expect(JSON.stringify(response.body.data).is.equal(JSON.stringify(result);
});
};
});
In the code above, it's just looping without to send the request, seems like a recursive issue or something else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看@ArtJomprozorov问题 CY请求reteries 。
同样的方法可以与某些mod一起使用。也许将尝试限制为要发送的数据项的总数,然后返回而不是丢弃错误。
Take a look at @ArtjomProzorov question Cy requests retries.
The same approach can work with some mods. Maybe set the attempts limit to the total number of data items to send, and return instead of throwing an error.