diff --git a/tests/cases/forms.html b/tests/cases/forms.html index ad4497f..a70001a 100644 --- a/tests/cases/forms.html +++ b/tests/cases/forms.html @@ -1,22 +1,15 @@ - Form tests - - - + - + @@ -53,12 +46,12 @@ - +
- + - + diff --git a/tests/cases/text/linethrough.html b/tests/cases/text/linethrough.html index 9326803..968862c 100644 --- a/tests/cases/text/linethrough.html +++ b/tests/cases/text/linethrough.html @@ -1,22 +1,15 @@ - Text-decoration:line-through tests - - - + + @@ -50,7 +43,7 @@ - + Creating content through JavaScript diff --git a/tests/selenium.js b/tests/selenium.js index 793767e..5e9b5fe 100644 --- a/tests/selenium.js +++ b/tests/selenium.js @@ -4,56 +4,78 @@ url = require("url"), path = require("path"), base64_arraybuffer = require('base64-arraybuffer'), PNG = require('png-js'), -fs = require("fs"), -port = 5555; +fs = require("fs"); -var server = http.createServer(function(request, response) { - var uri = url.parse(request.url).pathname, - filename = path.join(process.cwd(), "../" + uri); - fs.exists(filename, function(exists) { - if(!exists) { - response.writeHead(404, { - "Content-Type": "text/plain" - }); - response.write("404 Not Found\n"); - response.end(); - return; - } +function createServer(port) { + return http.createServer(function(request, response) { + var uri = url.parse(request.url).pathname, + filename = path.join(process.cwd(), "../" + uri); - if (fs.statSync(filename).isDirectory()) filename += '/index.html'; - - fs.readFile(filename, "binary", function(err, file) { - if(err) { - response.writeHead(500, { + fs.exists(filename, function(exists) { + if(!exists) { + response.writeHead(404, { "Content-Type": "text/plain" }); - response.write(err + "\n"); + response.write("404 Not Found\n"); response.end(); return; } - response.writeHead(200); - response.write(file, "binary"); - response.end(); + if (fs.statSync(filename).isDirectory()) filename += '/index.html'; + + fs.readFile(filename, "binary", function(err, file) { + if(err) { + response.writeHead(500, { + "Content-Type": "text/plain" + }); + response.write(err + "\n"); + response.end(); + return; + } + + response.writeHead(200); + response.write(file, "binary"); + response.end(); + }); }); + + }).listen(port); +} + +function walkDir(dir, done) { + var results = []; + fs.readdir(dir, function(err, list) { + if (err) return done(err); + var i = 0; + (function next() { + var file = list[i++]; + if (!file) return done(null, results); + file = dir + '/' + file; + fs.stat(file, function(err, stat) { + if (stat && stat.isDirectory()) { + walkDir(file, function(err, res) { + results = results.concat(res); + next(); + }); + } else { + results.push(file); + next(); + } + }); + })(); }); - -}).listen(port); - +}; function getPixelArray(base64, func) { var arraybuffer = base64_arraybuffer.decode(base64); (new PNG(arraybuffer)).decode(func); } -var browser = new webdriver({ - logging:false -}); +function testPage(browser, url, done) { -function testPage(url, done) { - browser.url("http://localhost:" + port + "/tests/" + url + "?selenium") + browser.url(url) .$(".html2canvas", 5000, function(){ this.execute(function(){ var canvas = $('.html2canvas')[0]; @@ -76,19 +98,57 @@ function testPage(url, done) { }); } -(function(pages) { +function runBrowsers(pages){ - (function processPage(page) { - testPage(page, function(result) { - if (pages.length > 0) { - processPage(pages.shift()); - } else { - browser.close(function(){ - server.close(); - }); - } - console.log(page, result); + var port = 5555, + stats = {}, + browsers = ["chrome", "firefox", "internet explorer"], + browsersDone = 0, + server = createServer(port), + numPages = pages.length; + + var browserDone = function() { + if (++browsersDone >= browsers.length) { + server.close(); + console.log(stats); + } + }; + + browsers.forEach(function(browserName){ + var browser = new webdriver({ + browser: browserName + }), + browserType; + + browser.status(function(browserInfo){ + browserType = [browserName, browser.version, browserInfo.os.name.replace(/\s+/g, "-").toLowerCase()].join("-"); + var date = new Date(), + obj = { + tests: {}, + date: date.toISOString() + }; + stats[browserType] = obj; + stats[browserName] = obj; + processPage(0); }); - })(pages.shift()); -})(["overflow.html", "forms.html", "lists.html"]); \ No newline at end of file + function processPage(index) { + var page = pages[index++]; + testPage(browser, "http://localhost:" + port + "/tests/" + page + "?selenium", function(result) { + if (numPages > index) { + processPage(index); + } else { + browser.close(browserDone); + } + stats[browserType].tests[page] = result; + }); + } + + }); +} + +walkDir("cases", function(err, results) { + if (err) throw err; + runBrowsers(results); +}); + diff --git a/tests/test.js b/tests/test.js index fecd191..8ffcd79 100644 --- a/tests/test.js +++ b/tests/test.js @@ -7,11 +7,12 @@ */ var h2cSelector, h2cOptions; (function(document, window) { - var scrStart = ''; - document.write(scrStart + '../external/jquery-1.6.2.js' + scrEnd); + var srcStart = ''; + + document.write(srcStart + '/external/jquery-1.6.2.js' + scrEnd); var html2canvas = ['Core', 'Generate', 'Parse', 'Preload', 'Queue', 'Renderer', 'Util', 'renderers/Canvas', 'plugins/jquery.plugin.html2canvas'], i; for (i = 0; i < html2canvas.length; ++i) { - document.write(scrStart + '../src/' + html2canvas[i] + '.js' + scrEnd); + document.write(srcStart + '/src/' + html2canvas[i] + '.js' + scrEnd); } window.onload = function() { h2cSelector = [document.body];