我有一个关于诗农测试的问题。我正在使用mochacasper我想捕获单击按钮后发送的 XMLHttpRequest。到目前为止我无法捕获请求...
casper.then(function () {
this.fill(...);
});
casper.then(function() {
this.click('#myButton');
});
casper.then(function () {
//I want to catch the request/response here
});
由于我使用的是测试环境数据库,因此我知道我的请求已发送,因为我的测试数据已添加到我的数据库中。
我尝试过sinon的useFakeXMLHttpRequest
,以及sinon的fakeServer
,但都不起作用。
那么我怎样才能捕获请求呢?
最佳答案
我已经用Artjom B.得出了一个“可行”的结果的评论。 这不完全是我所需要的,但目前已经足够了......
这是我的做法:
casper.then(function () {
this.click('button[data-hook="submitButton"]');
});
casper.waitForResource(function (resource) {
return resource.status === 201;
}, function () {
this.echo('Appointment has been created');
});
唯一的问题仍然是,我无法访问响应正文,但至少我可以检查状态是否正确。
关于javascript - 诗农catch xmlhttprequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30051103/