我需要在单击按钮时存根两个 API 调用,端点相同,但基本 url 不同。 意思是,如果我的存根看起来像:
cy.route('GET', 'apiEndPoint', response1);
cy.route('GET', 'apiEndPoint', response2);
即使我会做类似的事情:
cy.route('GET', 'http://baseurl1/apiEndPoint', response1);
cy.route('GET', 'http://baseurl2/apiEndPoint', response2);
当我点击按钮时,我仍然只得到 response2
。现在的情况是,通过单击一个按钮,两个 API 调用/存根必须一个接一个地发生。
因此,根据有关此问题的其他答案,我尝试执行以下操作:
cy.route('GET', 'apiEndPoint', response1).as('resonse1');
cy.route('GET', 'apiEndPoint', response2).as('response2');
然后当点击按钮时:
cy.get('.button').click();
cy.wait('@response1');
它仍然不起作用,因为 response1 已经被 response2 覆盖
所以我尝试做类似的事情:
cy.get('.button').click().wait(@response1).then(()=>cy.route('GET', 'http://baseurl2 /apiEndPoint', response2);)
仍然没有任何效果。总是只得到一个响应(响应 2,因为响应 1 被响应 2 覆盖) 我们仍在使用 cy.route 并且还没有升级到新的 cy.intercept()
知道如何在一次点击后从同一个端点获得两个响应吗?
非常感谢