Commit 9b3d9f51 9b3d9f51c2a6c3f9a62c1e1ffa839ec441a34092 by Nicolas Perriault

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

1 parent 1d797e66
...@@ -581,12 +581,7 @@ ...@@ -581,12 +581,7 @@
581 // http auth 581 // http auth
582 var httpAuthMatch = location.match(/^https?:\/\/(.+):(.+)@/i); 582 var httpAuthMatch = location.match(/^https?:\/\/(.+):(.+)@/i);
583 if (httpAuthMatch) { 583 if (httpAuthMatch) {
584 this.page.settings.userName = httpAuthMatch[1]; 584 this.setHttpAuth(httpAuthMatch[1], httpAuthMatch[2]);
585 this.page.settings.password = httpAuthMatch[2];
586 this.log("Adding authentication for user " + this.page.settings.userName, "info");
587 } else {
588 delete this.page.settings.userName;
589 delete this.page.settings.password;
590 } 585 }
591 this.page.open(location); 586 this.page.open(location);
592 return this; 587 return this;
...@@ -686,6 +681,26 @@ ...@@ -686,6 +681,26 @@
686 }, 681 },
687 682
688 /** 683 /**
684 * Sets HTTP authentication parameters.
685 *
686 * @param String username The HTTP_AUTH_USER value
687 * @param String password The HTTP_AUTH_PW value
688 * @return Casper
689 */
690 setHttpAuth: function(username, password) {
691 if (!this.started) {
692 throw "Casper must be started in order to use the setHttpAuth() method";
693 }
694 if (!isType(username, "string") || !isType(password, "string")) {
695 throw "Both username and password must be strings";
696 }
697 this.page.settings.userName = username;
698 this.page.settings.password = password;
699 this.log("Setting HTTP authentication for user " + username, "info");
700 return this;
701 },
702
703 /**
689 * Configures and starts Casper. 704 * Configures and starts Casper.
690 * 705 *
691 * @param String location An optional location to open on start 706 * @param String location An optional location to open on start
......