Created
December 7, 2011 00:01
-
-
Save peterbraden/1440705 to your computer and use it in GitHub Desktop.
WD tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys') | |
var tests = [] | |
exports.runTest= function(t, browser, cb){ | |
var err = function(e){ | |
sys.print('E') | |
console.log("\n Error: ", t[1], ">>> ", e.name, e.message, '\n', e.stack) | |
cb() | |
} | |
try{ | |
t[0](browser, cb, err); | |
sys.print('.') | |
} catch(e){ | |
sys.print('E') | |
err(e) | |
} | |
} | |
exports.test= function(name, t){ | |
t.name = name | |
tests.push([t, name]); | |
} | |
//wrapp callbacks in error handling | |
exports.callback = function(err, cb){ | |
return function(){ | |
try{ | |
cb.apply(this, arguments) | |
} catch (e){ | |
err(e) | |
} | |
} | |
} | |
exports.run = function(browser, url, cb){ | |
exports.base = url; | |
if (tests.length){ | |
exports.runTest(tests.shift(), browser, function(){exports.run(browser, url, cb)}) | |
} else { | |
console.log("DONE") | |
cb() | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var suite = require('./suite') | |
, assert = require('assert') | |
, c = suite.callback | |
, editor_id | |
//setup | |
suite.test("Loading page", function(browser, cb, e){ | |
browser.get(suite.base + '/basic.html', cb) | |
}) | |
//Sanity | |
suite.test("Testing page loaded jquery", function(browser, cb, e){ | |
browser.eval("window.$.fn.jquery", c(e, function(e,o){ | |
assert.equal(o,'1.4.2') | |
cb(); | |
})) | |
}) | |
//Sanity | |
suite.test("Testing page loaded yam.Editor", function(browser, cb, e){ | |
browser.eval("typeof window.yam.Editor", c(e, function(e,o){ | |
assert.equal(o,'function') | |
cb(); | |
})) | |
}) | |
//Sanity | |
suite.test("Testing editor element", function(browser, cb, e){ | |
browser.element("id", "editor", c(e, function(e,o){ | |
//store global: | |
editor_id = o | |
cb(); | |
})) | |
}) | |
//Sanity | |
suite.test("yam.Editor initial value", function(browser, cb, e){ | |
browser.eval("window.Ed.rawText()", c(e, function(e,o){ | |
assert.equal(o,'The quick brown fox jumps over the lazy dog') | |
cb(); | |
})) | |
}) | |
// Editor should parse bubble with transform to _quick_ | |
suite.test("yam.Editor initial value .text()", function(browser, cb, e){ | |
browser.eval("window.Ed.text();", c(e, function(e,o){ | |
assert.equal(e, null); | |
assert.equal(o,'The _quick_ brown fox jumps over the lazy dog') | |
cb(); | |
})) | |
}) | |
// val == text | |
suite.test("yam.Editor initial value .val()", function(browser, cb, e){ | |
browser.eval("window.Ed.text()",c(e, function(e,o){ | |
assert.equal(o,'The _quick_ brown fox jumps over the lazy dog') | |
cb(); | |
})) | |
}) | |
suite.test("Range method", function(browser, cb, e){ | |
browser.eval("window.Ed.range(1, 6).toString()",c(e, function(e,o){ | |
assert.equal(o,'he qu') | |
cb(); | |
})) | |
}) | |
// ==== Mutate field ======== | |
// Focus on field | |
suite.test("yam.Editor focus", function(browser, cb, e){ | |
browser.eval("window.Ed.focus()", c(e, function(er,o){ | |
//browser.active(c(e, function(e, o){ | |
//assert.equal(o, editor_id, "Editor id :" + editor_id + ", active: " + o); | |
// Not necessarily div active, could be child element ^ | |
cb(); | |
//})) | |
})) | |
}) | |
// Type 's' | |
suite.test("yam.Editor type 's'", function(browser, cb, e){ | |
browser.type(editor_id, ["s"], function(e){ | |
cb(); | |
}) | |
}) | |
suite.test("Change Event Fired", function(browser, cb, e){ | |
browser.eval("window._tests_changeFired", c(e, function(e,o){ | |
assert.equal(o, true) | |
cb(); | |
})) | |
}) | |
// new raw text | |
suite.test("new raw text after typing", function(browser, cb, e){ | |
browser.eval("window.Ed.rawText()", c(e, function(e,o){ | |
assert.equal(o,'The quick brown fox jumps over the lazy dogs') | |
cb(); | |
})) | |
}) | |
// new value/text | |
suite.test("New value after typing", function(browser, cb, e){ | |
browser.eval("window.Ed.text()", c(e, function(e,o){ | |
assert.equal(o,'The _quick_ brown fox jumps over the lazy dogs') | |
cb(); | |
})) | |
}) | |
// new value/text | |
suite.test("Wrap 'fox' in bubble", function(browser, cb, e){ | |
browser.eval("window.Ed.wrap(16, 19, '<span class="+'"bubble"' + " />').trigger('paste').text()", c(e, function(e,o){ | |
if (e){} | |
//throw e | |
assert.equal(o,'The _quick_ brown _fox_ jumps over the lazy dogs') | |
cb(); | |
})) | |
}) | |
// Caret Pos | |
suite.test("caret is at end", function(browser, cb, e){ | |
browser.eval("window.Ed.focus().caretPos()", c(e, function(e,o){ | |
assert.equal(o,44) | |
cb(); | |
})) | |
}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wd = require('wd') | |
, tests = require('./suite') | |
, basic = require('./basic') | |
, rich = require('./rich') | |
// Set up Command line options | |
var opts = require('nomnom') | |
.option('username', {}) | |
.option('apikey', {}) | |
.option('port', {default:80}) | |
.option('host', {default:"ondemand.saucelabs.com"}) | |
.option('url', {default: "http://peterbraden.co.uk/sandbox/Editable-Content/demo"}) | |
.option('browser', {default:"firefox"}) | |
.parse() | |
// Setup webdriver | |
if (opts.username) | |
var browser = wd.remote(opts.host, opts.port, opts.username, opts.apikey) | |
else | |
var browser = wd.remote(opts.host, opts.port) | |
browser.init({browserName:opts.browser}, function() { | |
browser.get(opts.url, function(){ | |
console.log("-- Browser Launched") | |
tests.run(browser, opts.url, function(){browser.close(function(){browser.quit()})}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
process.stdout.write()