Commit 09c19c30 09c19c309100f5ea5215dedac5f3c14dfbd85444 by Andrew de Andrade

Added settings to thenOpen()

1 parent 583868d9
......@@ -1245,10 +1245,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
......