Commit 9b3d9f51 9b3d9f51c2a6c3f9a62c1e1ffa839ec441a34092 by Nicolas Perriault

refs #29 - added Casper.setHttpAuth()in urls

1 parent 1d797e66
......@@ -581,12 +581,7 @@
// http auth
var httpAuthMatch = location.match(/^https?:\/\/(.+):(.+)@/i);
if (httpAuthMatch) {
this.page.settings.userName = httpAuthMatch[1];
this.page.settings.password = httpAuthMatch[2];
this.log("Adding authentication for user " + this.page.settings.userName, "info");
} else {
delete this.page.settings.userName;
delete this.page.settings.password;
this.setHttpAuth(httpAuthMatch[1], httpAuthMatch[2]);
}
this.page.open(location);
return this;
......@@ -686,6 +681,26 @@
},
/**
* Sets HTTP authentication parameters.
*
* @param String username The HTTP_AUTH_USER value
* @param String password The HTTP_AUTH_PW value
* @return Casper
*/
setHttpAuth: function(username, password) {
if (!this.started) {
throw "Casper must be started in order to use the setHttpAuth() method";
}
if (!isType(username, "string") || !isType(password, "string")) {
throw "Both username and password must be strings";
}
this.page.settings.userName = username;
this.page.settings.password = password;
this.log("Setting HTTP authentication for user " + username, "info");
return this;
},
/**
* Configures and starts Casper.
*
* @param String location An optional location to open on start
......