Permalink
Browse files

Error handling when registering to a Sel.Grid HUB.

  • Loading branch information...
1 parent 1fd571f commit 1f07c06a0b9df1b83e34a8e4b731f67bc4c4fcc5 @detro committed Nov 18, 2012
Showing with 34 additions and 27 deletions.
  1. +32 −25 src/hub_register.js
  2. +2 −2 test/config.ini
View
@@ -28,8 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* generate node configuration for this node */
var nodeconf = function(ip, port, hub) {
var ref$, hubHost, hubPort;
- ref$ = hub.match(/([\w\d\.]+):(\d+)/), hubHost = ref$[1], hubPort = ref$[2];
- hubPort = +hubPort;
+
+ ref$ = hub.match(/([\w\d\.]+):(\d+)/);
+ hubHost = ref$[1];
+ hubPort = +ref$[2]; //< ensure it's of type "number"
+
return {
capabilities: [{
browserName: "phantomjs",
@@ -56,29 +59,33 @@ var nodeconf = function(ip, port, hub) {
module.exports = {
register: function(ip, port, hub) {
- var page = require('webpage').create();
- port = +port;
- if(!hub.match(/\/$/)) {
- hub += '/';
- }
-
- /* Register with selenium grid server */
- page.open(hub + 'grid/register', {
- operation: 'post',
- data: JSON.stringify(nodeconf(ip, port, hub)),
- headers: {
- 'Content-Type': 'application/json'
+ try {
+ var page = require('webpage').create();
+ port = +port; //< ensure it's of type "number"
+ if(!hub.match(/\/$/)) {
+ hub += '/';
}
- }, function(status) {
- if(status !== 'success') {
- console.error("Unable to contact grid " + hub + ": " + status);
- phantom.exit(1);
- }
- if(page.framePlainText !== "ok") {
- console.error("Problem registering with grid " + hub + ": " + page.content);
- phantom.exit(1);
- }
- console.log("Registered with grid hub: " + hub + " (" + page.framePlainText + ")");
- });
+
+ /* Register with selenium grid server */
+ page.open(hub + 'grid/register', {
+ operation: 'post',
+ data: JSON.stringify(nodeconf(ip, port, hub)),
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ }, function(status) {
+ if(status !== 'success') {
+ console.error("Unable to contact grid " + hub + ": " + status);
+ phantom.exit(1);
+ }
+ if(page.framePlainText !== "ok") {
+ console.error("Problem registering with grid " + hub + ": " + page.content);
+ phantom.exit(1);
+ }
+ console.log("Registered with grid hub: " + hub + " (" + page.framePlainText + ")");
+ });
+ } catch (e) {
+ throw new Error("Could not register to Selenium Grid Hub: " + hub);
+ }
}
};
View
@@ -4,5 +4,5 @@ driver=phantomjs
#driver=http://localhost:8080
# PhantomJS specific config (change according to your installation)
-phantomjs_exec_path=/Users/detro/Workspaces/Qt/phantomjs/bin/phantomjs
-phantomjs_driver_path=/Users/detro/Workspaces/Qt/ghostdriver/src/main.js
+phantomjs_exec_path=/Users/detro/Workspaces/phantomjs/phantomjs/bin/phantomjs
+phantomjs_driver_path=/Users/detro/Workspaces/phantomjs/ghostdriver/src/main.js

0 comments on commit 1f07c06

Please sign in to comment.