Commit cd85a928 cd85a92889ea0464c3a1bf2d9440c5b5a329a7b5 by Nicolas Perriault

closes #173 - Added support for settings to casper.thenOpen

Contributed by @malendrew
2 parents 7bd5c1b5 a3e477cc
......@@ -1269,10 +1269,14 @@ Casper.prototype.thenEvaluate = function thenEvaluate(fn, context) {
* @return Casper
* @see Casper#open
*/
Casper.prototype.thenOpen = function thenOpen(location, then) {
Casper.prototype.thenOpen = function thenOpen(location, settings, then) {
"use strict";
if (!(settings && !utils.isFunction(settings))) {
then = settings;
settings = null;
}
this.then(this.createStep(function _step() {
this.open(location);
this.open(location, settings);
}, {
skipLog: true
}));
......
......@@ -22,7 +22,31 @@ var t = casper.test, current = 0, tests = [
username: 'bob',
password: 'sinclar'
}, "Casper.open() used the expected HTTP auth settings");
}
},
function(settings) {
t.assertEquals(settings, {
method: "get"
}, "Casper.thenOpen() used the expected GET settings");
},
function(settings) {
t.assertEquals(settings, {
method: "post",
data: "plop=42&chuck=norris"
}, "Casper.thenOpen() used the expected POST settings");
},
function(settings) {
t.assertEquals(settings, {
method: "put",
data: "plop=42&chuck=norris"
}, "Casper.thenOpen() used the expected PUT settings");
},
function(settings) {
t.assertEquals(settings, {
method: "get",
username: 'bob',
password: 'sinclar'
}, "Casper.thenOpen() used the expected HTTP auth settings");
},
];
casper.start();
......@@ -67,7 +91,43 @@ casper.open('tests/site/index.html', {
t.pass("Casper.open() can open and load a location using HTTP auth");
});
// GET with thenOpen
casper.thenOpen('tests/site/index.html').then(function() {
t.pass("Casper.thenOpen() can open and load a location using GET");
});
// POST with thenOpen
casper.thenOpen('tests/site/index.html', {
method: 'post',
data: {
plop: 42,
chuck: 'norris'
}
}, function() {
t.pass("Casper.thenOpen() can open and load a location using POST");
});
// PUT with thenOpen
casper.thenOpen('tests/site/index.html', {
method: 'put',
data: {
plop: 42,
chuck: 'norris'
}
}, function() {
t.pass("Casper.thenOpen() can open and load a location using PUT");
});
// HTTP Auth with thenOpen
casper.thenOpen('tests/site/index.html', {
method: 'get',
username: 'bob',
password: 'sinclar'
}, function() {
t.pass("Casper.thenOpen() can open and load a location using HTTP auth");
});
casper.run(function() {
this.removeAllListeners('open');
t.done();
});
});
\ No newline at end of file
......