Commit c528b220 c528b220c6d65fbaee2e30c9dd93fdf13d598606 by Nicolas Perriault

Merge pull request #460 from zeroem/update-request-url

Make Casper.currentResponse consistent with Casper.page 
2 parents 170fb289 fde75394
......@@ -2364,13 +2364,17 @@ function createPage(casper) {
casper.emit('load.finished', status);
casper.loadInProgress = false;
};
page.onNavigationRequested = function onNavigationRequested(url, type, lock, isMainFrame) {
casper.log(f('Navigation requested: url=%s, type=%s, lock=%s, isMainFrame=%s',
url, type, lock, isMainFrame), "debug");
page.onNavigationRequested = function onNavigationRequested(url, type, willNavigate, isMainFrame) {
casper.log(f('Navigation requested: url=%s, type=%s, willNavigate=%s, isMainFrame=%s',
url, type, willNavigate, isMainFrame), "debug");
if (isMainFrame && casper.requestUrl !== url) {
casper.navigationRequested = true;
if (willNavigate) {
casper.requestUrl = url;
}
}
casper.emit('navigation.requested', url, type, lock, isMainFrame);
casper.emit('navigation.requested', url, type, willNavigate, isMainFrame);
};
page.onPageCreated = function onPageCreated(popupPage) {
casper.emit('popup.created', popupPage);
......
/*global casper*/
/*jshint strict:false*/
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 consistent 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 consistent with the internal page'
);
});
}).run(function() {
test.done();
server.close();
});
});