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,22 +1,15 @@
<!--
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 16.7.2011
* @website http://hertzen.com
-->
<!DOCTYPE html>
<html>
<head>
<title>Form tests</title>
<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>
</head>
<body>
<body>
<input type="text" value="textbox" />
<input type="text" value="textbox" style="border:5px solid navy;" />
<input type="text" value="textbox" style="border:5px solid navy;height:40px;" />
@ -53,12 +46,12 @@
<input type="submit" value="Submit" style="width:200px;" />
<input type="Button" value="Button" style="width:200px;height:50px;" />
<input type="Reset" value="Reset" style="width:200px;height:50px;text-align:left;" />
<hr />
<textarea> </textarea>
<textarea style="border-width:10px;"></textarea>
<textarea> text </textarea>
<textarea style="border-width:10px;">text</textarea>
</body>

View File

@ -1,22 +1,15 @@
<!--
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 16.7.2011
* @website http://hertzen.com
-->
<!DOCTYPE html>
<html>
<head>
<title>Text-decoration:line-through tests</title>
<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">
function setUp() {
$('body').empty();
$.each(['arial','verdana','tahoma','courier new'],function(i,e){
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);
}
});
@ -34,23 +27,23 @@
.large{
font-size:24px;
}
div{
text-decoration:line-through;
}
.lineheight{
line-height:40px;
}
h2 {
clear:both;
}
</style>
</head>
<body>
<body>
Creating content through JavaScript
</body>
</html>

View File

@ -1,25 +1,18 @@
<!--
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 16.7.2011
* @website http://hertzen.com
-->
<!DOCTYPE html>
<html>
<head>
<title>Text-decoration:underline tests</title>
<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">
function setUp() {
$('body').empty();
$.each(['arial','verdana','tahoma','courier new'],function(i,e){
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);
}
}
});
}
</script>
@ -50,7 +43,7 @@
</style>
</head>
<body>
<body>
Creating content through JavaScript
</body>
</html>

View File

@ -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"]);
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;
(function(document, window) {
var scrStart = '<script type="text/javascript" src="', scrEnd = '"></script>';
document.write(scrStart + '../external/jquery-1.6.2.js' + scrEnd);
var srcStart = '<script type="text/javascript" src="', scrEnd = '"></script>';
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];