以下は casperjs と mockjax を使用する私のコードです。ただし、mockjax は ajax 呼び出しをインターセプトできません。モック レスポンスの代わりに ajax レスポンスを返します。また、 $.mockjax.mockedAjaxCalls().length これは何も出力しません。私がここで何をしているのか分かりますか?
$.mockjax.mockedAjaxCalls() の値を評価コンテキスト以外で実際に出力する方法はありますか?? mock4.png には、mockjax コールバックが発生していないことを示すスクリーンショットが表示されることに注意してください。
var casper = require("casper").create({
verbose: true,
logLevel: 'error',
clientScripts: ["jquery.mockjax.js", "jquery.js", "json2.js"]
});
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
})
casper.start('http://xyz:9000/abc', function() {
this.evaluate(function() {
this.capture('1.png')
$.mockjax({
url: '/foo1',
responseTime: 100,
dataType: 'json',
responseText: {
sessionTimeoutRedirectUrl: "https://foo/hello",
errorCode: "error.session.timeout"
}
});
});
this.capture('xyz123.png');
});
casper.waitForSelector('#order-wrapper', function() {
this.click('#method-field-cc');
this.capture('mock2.png');
});
casper.waitForSelector('#cc-card-number', function() {
this.capture('mock.png');
this.fillSelectors('form[id="cc-form"]', {
'input[id="cc-card-number"]': '4112344112344113',
'input[id="cc-first-name"]': 'first',
'input[id="cc-last-name"]': 'last',
'select[id="cc-expiry-month"]': '10',
'select[id="cc-expiry-year"]': '2016',
'input[id="tax-field-postal-code"]': '95051',
'input[id="cc-security-code"]': '123'
}, true);
this.click('#review-newcc');
this.capture('mock3.png');
});
casper.wait(1000, function() {
this.echo("I've waited for a second.");
casper.evaluate(function() {
this.echo("I've waited for a second." + $.mockjax.mockedAjaxCalls().length)
console.log($.mockjax.mockedAjaxCalls());
});
});
casper.evaluate(function() {
this.echo("I've waited for a second." + $.mockjax.mockedAjaxCalls().length)
});
casper.wait(1000, function() {
this.capture('mock4.png')
});
casper.run();