Skip to content
Browse files

Selenium2 support!! (use --sel2)

Also node .6 support
  • Loading branch information...
1 parent 169f53b commit 508a7d0818f7d006795aed5af815e4bd5bade775 @zzo committed Feb 8, 2012
View
19 README.md
@@ -7,7 +7,7 @@ Javascript Unit Testing Environment (JUTE)
Abstract
=========
-JUTE enables unobtrusive, automated [JavaScript](JavaScript.html) YUI3 unit testing with code coverage. Command line and web-based interfaces make JUTE easy to integrate with Hudson, developers, and even (gasp!) managers. There are 3 backends available to test your code: Selenium, Capture, PhantomJS/WebKit, and V8.
+JUTE enables unobtrusive, automated [JavaScript](JavaScript.html) YUI3 unit testing with code coverage. Command line and web-based interfaces make JUTE easy to integrate with Hudson, developers, and even (gasp!) managers. There are 3 backends available to test your code: Selenium (1, 2, and grid), Capture, PhantomJS/WebKit, and V8.
Requirements
@@ -168,6 +168,8 @@ This mode can currently only be accessed via the command line tool 'jute_submit_
Tests are expected to be in the standard test location and output will go into the standard output location as detailed above.
+To use WebDriver (Selenium2) you must use the '--sel2' flag on the command line
+
V8/NodeJS
----------
@@ -303,6 +305,10 @@ Of course --sel_host can either point to an individual Selenium RC host or a Sel
Note the docRoot/testDir prepended to the specified test files.
+For Selenium2 (WebDriver) use:
+
+ jute_submit_test --sel_host 10.3.4.45 [ --sel_browser firefox ] --test path/to/test/index.html --sel2
+
#### Selenium Snapshots
When running your tests thru Selenium you can get a screen snapshot of your test! If ANY Selenium test fails JUTE will take a screenshot which will be available along with all the usual test output.
@@ -313,19 +319,23 @@ If you specify '--snapshot' JUTE will ALWAYS take a screen snapshot AT THE END o
Will generate a screenshot of the browser when all tests included by index.html are complete.
+For Selenium2 (WebDriver):
+
+ jute_submit_test --sel_host 10.3.4.45 --snapshot --test path/to/test/index.html --sel2
+
#### Paralellized Selenium tests via Selenium Grid
IF you have a Selenium grid set up AND would like to paralellize your unit tests thru it ensure your remote-controls all provide the same environment (like *firefox).
-Now using the '--seleniums <#>' command line option you can specify how many remote-controls you want to spawn in parallel to run all of the submitted unit tests - SO:
+Now using the '--seleniums <#>' command line option you can specify how many remote-controls for Selenium Grid you want to spawn in parallel to run all of the submitted unit tests - SO:
jute_submit_test --sel_host 10.3.4.45 --seleniums 5 --test path/to/test/index.html --test path/to/other/test.html ....
Or even better to specify a krap-load of tests at once:
cd /path/to/tests && find . -name '*.html' -printf '%p?do_coverage=1\n' | jute_submit_test --sel_host 10.3.4.45 --seleniums 5 --test -
-This will attempt to spawn off 5 Selenium remote-controls - EACH WILL RUN 20% OF THE TESTS - to run your tests 5x faster.
+This will attempt to spawn off 5 Selenium Grid remote-controls - EACH WILL RUN 20% OF THE TESTS - to run your tests 5x faster.
Note this is DIFFERENT than capture mode testing where ALL tests run through ALL browsers - in this case EACH browser gets 1/5th of the total number of tests. This is because each remote-control is exactly the same!
@@ -558,6 +568,8 @@ All of your tests can be run thru Selenium - they all need to submitted at once
This will return once all tests have run.
+For Selenium2 append the '--sel2' option
+
Hudson Build Environment
-------------------------
@@ -594,6 +606,7 @@ Running JUTE/browser tests locally is a simple Makefile rule.
submit_selenium_tests:
cd $(LOCAL_TEST_DIR) && find . -not \\( -path "*/.svn/*" \\) -name '*.html' -printf '%p?do_coverage=$(DO_COVERAGE)\\n' | jute_submit_test --test - --sel_host $(SEL_HOST) --sel_browser $(SEL_BROWSER) --send_output
+Append '--sel2' for Selenium2/WebDriver
#### V8
View
9 backend/nodejute/jute/actions/common.js
@@ -99,14 +99,15 @@ module.exports = {
}
},
- takeSeleniumSnapshot: function(test, filename, component) {
+ takeSeleniumSnapshot: function(test, component) {
var soda = require('soda'), i
- b = soda.createClient({ host: test.sel_host });
+ , b = soda.createClient({ host: test.sel_host })
+ , filename = path.join(hub.config.outputDir, (common.makeSaneNames(component))[0], 'snapshot.png')
+ ;
if (!test.seleniumID) return;
- b.sid = test.seleniumID;
- filename = path.join(hub.config.outputDir, (common.makeSaneNames(component))[0], filename);
+ b.sid = test.seleniumID;
b.chain.windowFocus().getEval("window.moveTo(1,0); window.resizeTo(screen.availWidth, screen.availHeight);").end(function(err) {
if (!err) {
View
6 backend/nodejute/jute/actions/runTest.js
@@ -241,7 +241,11 @@ module.exports = {
});
seleniumIDs.forEach(function(selID) {
- hub.emit('action:selenium2Start', selID, req, res);
+ if (obj.sel2) {
+ hub.emit('action:selenium2Start', selID, req, res);
+ } else {
+ hub.emit('action:seleniumStart', selID, req, res);
+ }
});
} else if (obj.phantomjs) {
// Start up for a Selenium browser & Listen for results
View
84 backend/nodejute/jute/actions/startSelenium2.js
@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module.exports = {
- Create: function(hub) {
+ Create: function(hub, common) {
// Javascript is single threaded! We don't have to worry about concurrency!
var path = require('path'),
fs = require('fs'),
@@ -47,17 +47,15 @@ module.exports = {
function startSelenium(selID, req, res) {
var webdriverjs = require("webdriverjs"), cb,
- body = req.body,
- browser
+ body = req.body, browser
+ , url = 'http://' + (hub.config.host ? hub.config.host + ':' + hub.config.port : req.headers.host)
;
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 }
+ port: body.sel_port || 4444,
+ desiredCapabilities: { browserName: body.sel_browser || 'firefox' }
});
} catch(e) {
@@ -77,13 +75,8 @@ module.exports = {
// && keep track of requesting client for debug messages back...
// Callback for when the Selenium session is done
cb = function(err) {
+ hub.removeAllListeners(selID + 'snapshot');
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);
@@ -94,42 +87,39 @@ module.exports = {
};
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;
- }
- });
-
+ hub.on(selID + 'snapshot', function(test, component) {
+ browser.screenshot(function(screenshot) {
+ var path = require('path')
+ , filename = path.join(hub.config.outputDir, (common.makeSaneNames(component))[0], 'snapshot.png');
+
+ try {
+ var bb = new Buffer(screenshot.value, 'base64'),
+ msg = "Dumped snapshot for " + test.url + ' to ' + filename + "\n";
+ fs.writeFileSync(filename, bb, 0, bb.length);
+ common.addTestOutput(test, msg);
+ hub.emit(hub.LOG, hub.INFO, msg);
+ } catch(e) {
+ msg = "Error dumping snapshot file " + filename + ": " + e + "\n";
+ common.addTestOutput(test, msg);
+ hub.emit(hub.LOG, hub.ERROR, msg);
}
+
+ hub.emit('action:doneDone', null, test);
});
-*/
+ });
+
+ browser
+ .init(function() {
+ // 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;
+ test.sel2 = true;
+ }
+ });
+ })
+ .url(url + '/?selenium=' + selID);
}
}
View
6 backend/nodejute/jute/actions/testReport.js
@@ -174,7 +174,11 @@ module.exports = {
// only if a test fails
if ((!succeeded || test.snapshot) && req.session.selenium) {
hub.emit(hub.LOG, hub.INFO, 'Taking a Selenium snapshot of: ' + test.url);
- common.takeSeleniumSnapshot(test, path.basename(names[0], 'xml') + '.png', obj.name);
+ if (test.sel2) {
+ hub.emit(test.browser + 'snapshot', test, obj.name);
+ } else {
+ common.takeSeleniumSnapshot(test, obj.name);
+ }
} else {
hub.emit('action:doneDone', null, test);
}
View
2 backend/nodejute/package.json
@@ -2,7 +2,7 @@
"name": "jute",
"description": "Javascript Unit Test Environment",
"keywords": ["selenium", "test", "testing", "unit", "tests"],
- "version": "0.0.58",
+ "version": "0.0.59",
"author": "Mark Ethan Trostler <mark@zzo.com>",
"preferGlobal": true,
"bin" : {
View
12 backend/nodejute/submit_test.js
@@ -41,7 +41,7 @@ var config = (require('./getConfig'))(),
events = require("events"),
eventHubF = function() { events.EventEmitter.call(this); },
args = opt
- .usage('Usage: $0 --test [testfile] [ --test [another testfile] ] [ --host [JUTE host] ] [ --port [JUTE host port] ] [ --sel_host [Selenium host] ] [ --sel_browser [Selenium browser spec] ] [ --seleniums # ] [ --load ] ] [ --send_output ] [ --wait ] [ --clear_results ] [ -v8 ] [ --status ] [ --snapshot ] [ --retry ] [ --phantomjs ] [ --screen # ]')
+ .usage('Usage: $0 --test [testfile] [ --test [another testfile] ] [ --host [JUTE host] ] [ --port [JUTE host port] ] [ --sel_host [Selenium host] ] [ --sel_browser [Selenium browser spec] ] [ --seleniums # ] [ --sel2 ] [ --load ] ] [ --send_output ] [ --wait ] [ --clear_results ] [ -v8 ] [ --status ] [ --snapshot ] [ --retry ] [ --phantomjs ] [ --screen # ]')
.alias('t', 'test')
.alias('h', 'host')
.alias('p', 'port')
@@ -56,6 +56,7 @@ var config = (require('./getConfig'))(),
.alias('r', 'retry')
.alias('ph', 'phantomjs')
.alias('sc', 'screen')
+ .alias('s2', 'sel2')
.default('host', (config && config.host) || os.hostname())
.default('port', (config && config.port) || 8080)
.default('send_output', false)
@@ -67,6 +68,7 @@ var config = (require('./getConfig'))(),
.default('clear_results', false)
.default('seleniums', 1)
.default('sel_browser', '*firefox')
+ .default('sel2', 0)
.default('retry', 0)
.default('screen', 0)
.describe('test', 'Test file to run - relative to docRoot/testDir (npm set jute.testDir) - can specify multiple of these')
@@ -75,6 +77,7 @@ var config = (require('./getConfig'))(),
.describe('sel_host', 'Hostname of Selenium RC or Grid Server (if not specified test(s) will run in all CURRENTLY captured browsers)')
.describe('sel_browser', 'Selenium browser specification')
.describe('seleniums', 'Number of Selenium browsers to run tests in parallel')
+ .describe('sel2', 'Use Selenium2')
.describe('load', 'Load up tests but do not run them immediately')
.describe('snapshot', 'Dump a snapshot at end of test (Selenium only!)')
.describe('send_output', 'For Selenium tests ONLY - send status messages back while running')
@@ -161,9 +164,12 @@ eventHub.on('tests', function(tests) {
// Toss in Selenium stuff
if (args.sel_host) {
- juteArgs.sel_host = args.sel_host;
+ juteArgs.sel_host = args.sel_host;
juteArgs.sel_browser = args.sel_browser;
- juteArgs.seleniums = args.seleniums;
+ juteArgs.seleniums = args.seleniums;
+ if (args.sel2) {
+ juteArgs.sel2 = 1;
+ }
if (args.snapshot) {
juteArgs.snapshot = 1;
}

0 comments on commit 508a7d0

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