Permalink
Browse files

start up fixes

use node .6
beginnings of sel2
  • Loading branch information...
zzo committed Feb 7, 2012
1 parent c452d36 commit 169f53b0a32aa317f88be89d527224eaa30e9c92
Showing with 3,153 additions and 42 deletions.
  1. +1 −1 backend/nodejute/jute/actions/runTest.js
  2. +137 −0 backend/nodejute/jute/actions/startSelenium2.js
  3. +50 −18 backend/nodejute/jute/configure.js
  4. +6 −14 backend/nodejute/jute/daemon.js
  5. +14 −8 backend/nodejute/jute_backend.js
  6. +68 −0 backend/nodejute/node_modules/webdriverjs/all.commands.txt
  7. +25 −0 backend/nodejute/node_modules/webdriverjs/lib/asserts/textContains.js
  8. +30 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/click.js
  9. +18 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/dragAndDrop.js
  10. +13 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/end.js
  11. +119 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/facebookLogin.js
  12. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getAttribute.js
  13. +29 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getCssProperty.js
  14. +30 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getElementCssProperty.js
  15. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getElementSize.js
  16. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getLocation.js
  17. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getLocationInView.js
  18. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getSize.js
  19. +29 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getTagName.js
  20. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getText.js
  21. +26 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getTitle.js
  22. +29 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/getValue.js
  23. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/isVisible.js
  24. +31 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/lazySetValue.js
  25. +30 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/moveToObject.js
  26. +5 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/pause.js
  27. +25 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/saveScreenshot.js
  28. +32 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/sendKeys.js
  29. +29 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/setValue.js
  30. +29 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/submitForm.js
  31. +35 −0 backend/nodejute/node_modules/webdriverjs/lib/commands/waitFor.js
  32. +17 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/buttonDown.js
  33. +17 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/buttonUp.js
  34. +29 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/element.js
  35. +21 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdAttribute.js
  36. +19 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdClick.js
  37. +21 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdCssProperty.js
  38. +22 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdDisplayed.js
  39. +19 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdKeys.js
  40. +17 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdLocation.js
  41. +17 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdLocationInView.js
  42. +20 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdName.js
  43. +17 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdSize.js
  44. +20 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdText.js
  45. +50 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elementIdValue.js
  46. +26 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/elements.js
  47. +21 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/execute.js
  48. +26 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/frame.js
  49. +97 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/init.js
  50. +45 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/moveTo.js
  51. +16 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/screenshot.js
  52. +57 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/session.js
  53. +17 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/status.js
  54. +23 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/submit.js
  55. +18 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/title.js
  56. +58 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/url.js
  57. +44 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/value.js
  58. +19 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/window.js
  59. +19 −0 backend/nodejute/node_modules/webdriverjs/lib/protocol/windowHandles.js
  60. +12 −0 backend/nodejute/node_modules/webdriverjs/lib/tests/cssPropertyEquals.js
  61. +13 −0 backend/nodejute/node_modules/webdriverjs/lib/tests/titleEquals.js
  62. +12 −0 backend/nodejute/node_modules/webdriverjs/lib/tests/visible.js
  63. +921 −0 backend/nodejute/node_modules/webdriverjs/lib/webdriverjs.js
  64. +23 −0 backend/nodejute/node_modules/webdriverjs/package.json
  65. +1 −0 backend/nodejute/node_modules/wordwrap/.npmignore
  66. +70 −0 backend/nodejute/node_modules/wordwrap/README.markdown
  67. +10 −0 backend/nodejute/node_modules/wordwrap/example/center.js
  68. +3 −0 backend/nodejute/node_modules/wordwrap/example/meat.js
  69. +76 −0 backend/nodejute/node_modules/wordwrap/index.js
  70. +37 −0 backend/nodejute/node_modules/wordwrap/package.json
  71. +30 −0 backend/nodejute/node_modules/wordwrap/test/break.js
  72. +63 −0 backend/nodejute/node_modules/wordwrap/test/idleness.txt
  73. +31 −0 backend/nodejute/node_modules/wordwrap/test/wrap.js
  74. +2 −1 backend/nodejute/package.json
@@ -241,7 +241,7 @@ module.exports = {
});
seleniumIDs.forEach(function(selID) {
- hub.emit('action:seleniumStart', selID, req, res);
+ hub.emit('action:selenium2Start', selID, req, res);
});
} else if (obj.phantomjs) {
// Start up for a Selenium browser & Listen for results
@@ -0,0 +1,137 @@
+/*
+Copyright (c) 2011, Yahoo! Inc.
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of Yahoo! Inc. nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Yahoo! Inc.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+module.exports = {
+ Create: function(hub) {
+ // Javascript is single threaded! We don't have to worry about concurrency!
+ var path = require('path'),
+ fs = require('fs'),
+ cache = hub.cache
+ ;
+
+ // Events I care about
+ hub.addListener('action:selenium2Start', startSelenium);
+
+ function startSelenium(selID, req, res) {
+ var webdriverjs = require("webdriverjs"), cb,
+ body = req.body,
+ browser
+ ;
+
+ try {
+ //var client = webdriverjs.remote({host: "xx.xx.xx.xx"}); // to run it on a remote webdriver/selenium server
+ //url: 'http://' + (hub.config.host ? hub.config.host + ':' + hub.config.port : req.headers.host),
+
+ browser = webdriverjs.remote({
+ host: body.sel_host,
+ desiredCapabilities: { browserName: body.sel_browser }
+ });
+
+ } catch(e) {
+ hub.emit('action:seleniumDone', 'Cannot connect to Selenium server at ' + body.sel_host + ': ' + e, selID);
+ return;
+ }
+
+ // Give Selenium 1000 minutes to finish - should be good - 16 hours baby!
+ req.socket.setTimeout(60000000, function() {
+ hub.emit(hub.LOG, hub.ERROR, 'Selenium taking too long - giving up');
+ cb();
+ });
+
+ cache.connections[selID] = res; // our link back to the requesting client for status messages
+
+ // called when all Selenium tests are complete for this browser
+ // && keep track of requesting client for debug messages back...
+ // Callback for when the Selenium session is done
+ cb = function(err) {
+ if (!err) {
+ /*
+ browser.chain.testComplete().end(function(err) {
+ delete cache.connections[selID]; // done with status updates
+ hub.emit('action:seleniumDone', err, selID);
+ });
+ */
+ browser.end(function() {
+ delete cache.connections[selID]; // done with status updates
+ hub.emit('action:seleniumDone', err, selID);
+ });
+ } else {
+ hub.emit('action:seleniumDone', err, selID);
+ }
+ };
+ cb = hub.once(selID + 'finished', cb);
+
+ browser
+ .init()
+ .url('/?selenium=' + selID);
+
+ hub.emit(hub.LOG, hub.INFO, "Selenium up and running: " + browser.sessionId);
+ // If this is one of the tests that are going to run in the
+ // Selenium session, tag it with the Selenium token
+ cache.tests_to_run.forEach(function(test) {
+ if (test.browser === selID) {
+ test.seleniumID = browser.sessionId;
+ }
+ });
+
+/*
+ browser.
+ chain.
+ session().
+ open('/?selenium=' + selID).
+ waitForPageToLoad(10000).
+ end(function(err) {
+ if (err) {
+ var msg = 'Error starting/waiting for Selenium page to load: ' + err;
+ hub.emit('seleniumTestsFinished', err);
+ } else {
+ hub.emit(hub.LOG, hub.INFO, "Selenium up and running: " + browser.sid);
+ // If this is one of the tests that are going to run in the
+ // Selenium session, tag it with the Selenium token
+ cache.tests_to_run.forEach(function(test) {
+ if (test.browser === selID) {
+ test.seleniumID = browser.sid;
+ }
+ });
+
+ }
+ });
+*/
+ }
+ }
+
+};
+
@@ -44,12 +44,13 @@ Create: function(hub) {
function configure() {
var config = {
- port: 8080,
+ port: 5883,
docRoot: '/var/www',
testDir: 'test/',
outputDir: 'output/',
java: '',
logFormat: '',
+ logFile: '/tmp/jute.log',
testRegex: '.html$',
inject: 1,
screen: 0,
@@ -59,6 +60,8 @@ Create: function(hub) {
exec = require('child_process').exec,
fs = require('fs');
+ hub.config = config;
+
// Suck in NPM config variables
for (var key in config) {
var val = process.env['npm_package_config_' + key];
@@ -67,6 +70,14 @@ Create: function(hub) {
}
}
+ try {
+ config.logFD = fs.openSync(config.logFile, "w");
+ } catch(e) {
+ console.error('Cannot open logilfe: ' + e);
+ hub.emit('configureError', { name: 'logFile', value: config.logFile, error: e } );
+ return;
+ }
+
try {
var stat = fs.statSync(config.docRoot);
if (!stat.isDirectory()) {
@@ -85,39 +96,60 @@ Create: function(hub) {
try {
fs.statSync(config.outputDir);
} catch(e) {
- fs.mkdirSync(config.outputDir, 0777)
+ try {
+ fs.mkdirSync(config.outputDir, 0777)
+ } catch(e2) {
+ hub.emit(hub.LOG, hub.ERROR, "Cannot make output dir: " + e2);
+ hub.emit('configureError', { name: 'outputDir', value: config.outputDir, error: e2 } );
+ return;
+ }
}
config.testDirWeb = config.testDir;
config.testDir = path.join(config.docRoot, config.testDir);
try {
fs.statSync(config.testDir);
} catch(e) {
- fs.mkdirSync(config.testDir, 0777)
+ try {
+ fs.mkdirSync(config.testDir, 0777)
+ } catch(e2) {
+ hub.emit(hub.LOG, hub.ERROR, "Cannot make test dir: " + e2);
+ hub.emit('configureError', { name: 'testDir', value: config.testDir, error: e2 } );
+ return;
+ }
}
// Find Java executable
- if (process.env.JAVA_HOME) {
- config.java = path.join(process.env.JAVA_HOME, 'bin', 'java');
- } else if (!config.java) {
+ if (!config.java) {
exec('which java', function (error, stdout, stderr) {
if (!error) {
config.java = stdout.trim();
}
+ try {
+ var stat = fs.statSync(config.java);
+ if (!stat.isFile()) {
+ throw 'foobie';
+ }
+ } catch(e) {
+ hub.emit(hub.LOG, hub.ERROR, '** Cannot find "java" executable in PATH **');
+ hub.emit(hub.LOG, hub.ERROR, 'Set the "java" configuration variable (% npm config set jute:java <path>)');
+ hub.emit(hub.LOG, hub.ERROR, 'Or add the "java" executable to your PATH');
+ hub.emit('configureError', { name: 'java', value: config.java, error: e } );
+ return;
+ }
});
- }
-
- try {
- var stat = fs.statSync(config.java);
- if (!stat.isFile()) {
- throw 'foobie';
+ } else {
+ try {
+ var stat = fs.statSync(config.java);
+ if (!stat.isFile()) {
+ throw 'foobie';
+ }
+ } catch(e) {
+ hub.emit(hub.LOG, hub.ERROR, '** Cannot find "java" executable **');
+ hub.emit(hub.LOG, hub.ERROR, 'NPM java config variable improperly set: ' + config.java);
+ hub.emit('configureError', { name: 'java', value: config.java, error: e } );
+ return;
}
- } catch(e) {
- hub.emit(hub.LOG, hub.ERROR, '** Cannot find "java" executable **');
- hub.emit(hub.LOG, hub.ERROR, 'Set $JAVA_HOME OR set the "java" configuration variable (% npm config set jute:java <path>)');
- hub.emit(hub.LOG, hub.ERROR, 'Or add the "java" executable to your PATH');
- hub.emit('configureError', { name: 'java', value: config.java, error: e } );
- return;
}
// Make sure output directory is writable for grins...
@@ -1,4 +1,4 @@
-#!/usr/bin/env node
+#!env node
var opt = require( "optimist"),
fs = require('fs'),
@@ -9,12 +9,11 @@ var opt = require( "optimist"),
.describe('start', 'Start JUTE')
.describe('stop', 'Stop JUTE')
.argv,
- logfile = process.env['npm_package_config_logfile'],
- pidfile = process.env['npm_package_config_pidfile']
+ pidfile = process.env['npm_package_config_pidfile'] || '/tmp/jute.pid'
;
function start() {
- var spawn = require('child_process').spawn, fd, jute;
+ var spawn = require('child_process').spawn, jute;
try {
var pid = fs.readFileSync(pidfile);
@@ -36,20 +35,13 @@ function start() {
}
try {
- fd = fs.openSync(logfile, 'w');
- } catch(e) {
- console.error('Error opening logfile: ' + e);
- return;
- }
-
- try {
- jute = spawn('./jute_backend.js', [], { setsid: false, customFds: [-1, fd, fd], cwd: process.cwd() });
+ jute = spawn('./jute_backend.js', [], { setsid: false, cwd: process.cwd() });
} catch(e) {
console.error("Error spawing JUTE: " + e);
process.exit(1);
}
- jute.on('exit', function() { fs.unlinkSync(pidfile); });
+ jute.on('exit', function() { try { fs.unlinkSync(pidfile); } catch(e) {} });
try {
fs.writeFileSync(pidfile, "" + jute.pid);
@@ -79,4 +71,4 @@ if (args.start) {
console.error("You must specify 'start' or 'stop'!");
}
-process.exit(0);
+//process.exit(0);
@@ -42,8 +42,7 @@ var util = require('util'),
server = require('./jute/server'),
actions = require('./jute/actions'),
common = require('./jute/actions/common'),
- eventHubF = function() { events.EventEmitter.call(this); this.LOG = 'log'; this.ERROR = 'error'; this.INFO = 'info'; },
- pidFile = '/tmp/jute.pid'
+ eventHubF = function() { events.EventEmitter.call(this); this.LOG = 'log'; this.ERROR = 'error'; this.INFO = 'info'; }
;
/**
@@ -55,20 +54,27 @@ var eventHub = new eventHubF();
// Prime cache
eventHub.cache = { browsers: {}, tests_to_run: [], connections: {}, currentTest: {} };
-configure.Create(eventHub);
-actions.Create(eventHub, common.Create(eventHub));
-server.Create(eventHub);
-
// Some app-wide helpers
eventHub.addListener(eventHub.LOG, function(sev, str) {
+ var output;
if (sev === eventHub.ERROR) {
- console.log('ERROR: ' + str);
+ output = 'ERROR: ' + str + "\n";
} else {
- console.log(str);
+ output = str + "\n";
}
+ if (eventHub.config.logFD) {
+ fs.writeSync(eventHub.config.logFD, output);
+ } else {
+ console.error(str);
+ }
});
+configure.Create(eventHub);
+actions.Create(eventHub, common.Create(eventHub));
+server.Create(eventHub);
+
+
// Get Party Started
eventHub.on('configureError', function(obj) {
eventHub.emit(eventHub.LOG, eventHub.ERROR, "Configuration error for " + obj.name + ': ' + obj.error);
Oops, something went wrong.

0 comments on commit 169f53b

Please sign in to comment.