Skip to content
Browse files

Extending CLI interface to define IP for Sel.HUB

Passing "IP:PORT" instead of just "PORT" it's possible
to inform GhostDriver of the IP to publicise when
registering to the Selenium HUB.

Fix Issue #104.
  • Loading branch information...
1 parent 279b6c5 commit a733e34d1614313a4ac14bcd676fdf044b864fe9 @detro committed Oct 31, 2012
Showing with 24 additions and 8 deletions.
  1. +3 −3 src/hub_register.js
  2. +21 −5 src/main.js
View
6 src/hub_register.js
@@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* generate node configuration for this node */
-var nodeconf = function(port, hub){
+var nodeconf = function(ip, port, hub){
var ref$, hubHost, hubPort;
ref$ = hub.match(/([\w\d\.]+):(\d+)/), hubHost = ref$[1], hubPort = ref$[2];
hubPort = +hubPort;
@@ -48,8 +48,8 @@ var nodeconf = function(port, hub){
register: true,
registerCycle: 5000,
role: "wd",
- url: "http://127.0.0.1:" + port,
- remoteHost: "http://127.0.0.1:" + port
+ url: "http://" + ip + ":" + port,
+ remoteHost: "http://" + ip + ":" + port
}
};
};
View
26 src/main.js
@@ -33,7 +33,10 @@ var ghostdriver = {
},
server = require('webserver').create(),
router,
- parseURI;
+ parseURI,
+ listenOn,
+ listenOnIp = "127.0.0.1",
+ listenOnPort = "8080";
// Enable "strict mode" for the 'parseURI' library
parseURI = require("./third_party/parseuri.js");
@@ -53,12 +56,25 @@ phantom.injectJs("webelementlocator.js");
// HTTP Request Router
router = new ghostdriver.RouterReqHand();
+// Check if parameters were given, regarding the "ip:port" to listen to
+if (ghostdriver.system.args[1]) {
+ if (ghostdriver.system.args[1].indexOf(':') >= 0) {
+ listenOn = ghostdriver.system.args[1].split(':');
+ listenOnIp = listenOn[0];
+ listenOnPort = listenOn[1];
+ } else {
+ listenOnPort = ghostdriver.system.args[1];
+ }
+}
+
// Start the server
-if (server.listen(ghostdriver.system.args[1] || 8080, router.handle)) {
+if (server.listen(listenOnPort, router.handle)) {
console.log('Ghost Driver running on port ' + server.port);
- var reg = ghostdriver.hub.register;
- if (ghostdriver.system.args[2])
- reg(ghostdriver.system.args[1], ghostdriver.system.args[2]);
+
+ // If parameters regarding a Selenium Grid HUB were given, register to it!
+ if (ghostdriver.system.args[2]) {
+ ghostdriver.hub.register(listenOnIp, listenOnPort, ghostdriver.system.args[2]);
+ }
} else {
console.error("ERROR: Could not start Ghost Driver");
phantom.exit();

0 comments on commit a733e34

Please sign in to comment.
Something went wrong with that request. Please try again.