webdriver testing

This commit is contained in:
Niklas von Hertzen 2012-12-27 23:06:47 +02:00
parent 4684177df8
commit 582d10e00d
5 changed files with 125 additions and 85 deletions

View File

@ -1,16 +1,9 @@
<!--
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 16.7.2011
* @website http://hertzen.com
-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Form tests</title> <title>Form tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="#" type="text/css" rel="stylesheet"> <script type="text/javascript" src="../test.js"></script>
<script type="text/javascript" src="test.js"></script>
<style> <style>
</style> </style>

View File

@ -1,22 +1,15 @@
<!--
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 16.7.2011
* @website http://hertzen.com
-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Text-decoration:line-through tests</title> <title>Text-decoration:line-through tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="#" type="text/css" rel="stylesheet"> <script type="text/javascript" src="../../test.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function setUp() { function setUp() {
$('body').empty(); $('body').empty();
$.each(['arial','verdana','tahoma','courier new'],function(i,e){ $.each(['arial','verdana','tahoma','courier new'],function(i,e){
var div = $('<div />').css('font-family',e).appendTo('body'); var div = $('<div />').css('font-family',e).appendTo('body');
for(var i=0;i<=20;i++){ for(var i=0;i<=10;i++){
$('<div />').text('Testing texts').css('margin-top',1).css('border','1px solid black').css('font-size',(16+i*6)).appendTo(div); $('<div />').text('Testing texts').css('margin-top',1).css('border','1px solid black').css('font-size',(16+i*6)).appendTo(div);
} }
}); });

View File

@ -1,22 +1,15 @@
<!--
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 16.7.2011
* @website http://hertzen.com
-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Text-decoration:underline tests</title> <title>Text-decoration:underline tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="#" type="text/css" rel="stylesheet"> <script type="text/javascript" src="../../test.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function setUp() { function setUp() {
$('body').empty(); $('body').empty();
$.each(['arial','verdana','tahoma','courier new'],function(i,e){ $.each(['arial','verdana','tahoma','courier new'],function(i,e){
var div = $('<div />').css('font-family',e).appendTo('body'); var div = $('<div />').css('font-family',e).appendTo('body');
for(var i=0;i<=20;i++){ for(var i=0;i<=10;i++){
$('<div />').text('Testing texts').css('margin-top',1).css('border','1px solid black').css('font-size',(16+i*6)).appendTo(div); $('<div />').text('Testing texts').css('margin-top',1).css('border','1px solid black').css('font-size',(16+i*6)).appendTo(div);
} }

View File

@ -4,56 +4,78 @@ url = require("url"),
path = require("path"), path = require("path"),
base64_arraybuffer = require('base64-arraybuffer'), base64_arraybuffer = require('base64-arraybuffer'),
PNG = require('png-js'), PNG = require('png-js'),
fs = require("fs"), fs = require("fs");
port = 5555;
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) { function createServer(port) {
if(!exists) { return http.createServer(function(request, response) {
response.writeHead(404, { var uri = url.parse(request.url).pathname,
"Content-Type": "text/plain" filename = path.join(process.cwd(), "../" + uri);
});
response.write("404 Not Found\n");
response.end();
return;
}
if (fs.statSync(filename).isDirectory()) filename += '/index.html'; fs.exists(filename, function(exists) {
if(!exists) {
fs.readFile(filename, "binary", function(err, file) { response.writeHead(404, {
if(err) {
response.writeHead(500, {
"Content-Type": "text/plain" "Content-Type": "text/plain"
}); });
response.write(err + "\n"); response.write("404 Not Found\n");
response.end(); response.end();
return; return;
} }
response.writeHead(200); if (fs.statSync(filename).isDirectory()) filename += '/index.html';
response.write(file, "binary");
response.end(); 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) { function getPixelArray(base64, func) {
var arraybuffer = base64_arraybuffer.decode(base64); var arraybuffer = base64_arraybuffer.decode(base64);
(new PNG(arraybuffer)).decode(func); (new PNG(arraybuffer)).decode(func);
} }
var browser = new webdriver({
logging:false
});
function testPage(browser, url, done) {
function testPage(url, done) { browser.url(url)
browser.url("http://localhost:" + port + "/tests/" + url + "?selenium")
.$(".html2canvas", 5000, function(){ .$(".html2canvas", 5000, function(){
this.execute(function(){ this.execute(function(){
var canvas = $('.html2canvas')[0]; var canvas = $('.html2canvas')[0];
@ -76,19 +98,57 @@ function testPage(url, done) {
}); });
} }
(function(pages) { function runBrowsers(pages){
(function processPage(page) { var port = 5555,
testPage(page, function(result) { stats = {},
if (pages.length > 0) { browsers = ["chrome", "firefox", "internet explorer"],
processPage(pages.shift()); browsersDone = 0,
} else { server = createServer(port),
browser.close(function(){ numPages = pages.length;
server.close();
}); var browserDone = function() {
} if (++browsersDone >= browsers.length) {
console.log(page, result); 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"]); 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);
});

View File

@ -7,11 +7,12 @@
*/ */
var h2cSelector, h2cOptions; var h2cSelector, h2cOptions;
(function(document, window) { (function(document, window) {
var scrStart = '<script type="text/javascript" src="', scrEnd = '"></script>'; var srcStart = '<script type="text/javascript" src="', scrEnd = '"></script>';
document.write(scrStart + '../external/jquery-1.6.2.js' + scrEnd);
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; var html2canvas = ['Core', 'Generate', 'Parse', 'Preload', 'Queue', 'Renderer', 'Util', 'renderers/Canvas', 'plugins/jquery.plugin.html2canvas'], i;
for (i = 0; i < html2canvas.length; ++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() { window.onload = function() {
h2cSelector = [document.body]; h2cSelector = [document.body];