Below is my code which uses casperjs and mockjax . However , mockjax is not able to intercept the ajax call . It returns the ajax response instead of the mock response . Also, $.mockjax.mockedAjaxCalls().length this does not print anything . Any idea what I am doing here?
Is there any way I could actually print the value of $.mockjax.mockedAjaxCalls() other than outside evaluate context ??. Please note that mock4.png does show a screenshot indicating that the mockjax callback has not happened .
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();