Commit 8a0bc5e7 8a0bc5e7aaf22db891338d3de0c2bdc94ebf7a63 by Darrell Hamilton

Update currentResponse on Navigation

Previously, when clicking on a link in a page or submitting a form,
Casper.page would be updated to reflect the newly loaded page, but
Casper.currentResponse would not.  This caused the response passed to
'then' callbacks to only reflect the initial page load.  This patch
resolves that issue so that Casper's page and currentResponse are
consistent and subsequent 'then' call backs receive the response of the
most recent main page load.
1 parent f6c19810
......@@ -2267,6 +2267,10 @@ function createPage(casper) {
url, type, willNavigate, isMainFrame), "debug");
if (isMainFrame && casper.requestUrl !== url) {
casper.navigationRequested = true;
if(willNavigate) {
casper.requestUrl = url;
}
}
casper.emit('navigation.requested', url, type, willNavigate, isMainFrame);
};
......
var server = require('webserver').create();
var service = server.listen(8090, function(request, response) {
response.statusCode = 200;
response.setHeader('Content-type', 'text/html');
response.write('<a href="/link">a link</a>');
response.write('<form action="/form" method="POST"><input type="submit" /></form>');
response.close();
});
casper.test.begin('Link Navigation updates response', function(test) {
casper.start('http://localhost:8090', function(response) {
casper.click('a');
casper.then(function(response) {
test.assertUrlMatch(
/\/link$/,
'URL matches anchor href'
);
test.assertEquals(
response.url,
casper.page.url,
'response is consisitent with the internal page'
);
});
}).run(function() {
test.done();
});
});
casper.test.begin('Form Submittal updates the response', function(test) {
casper.start('http://localhost:8090', function(response) {
casper.fill('form', {}, true);
casper.then(function(response) {
test.assertUrlMatch(
/\/form$/,
'URL matches form action'
);
test.assertEquals(
response.url,
casper.page.url,
'response is consisitent with the internal page'
);
});
}).run(function() {
test.done();
server.close();
});
});