mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
webdriver testing
This commit is contained in:
parent
4684177df8
commit
582d10e00d
@ -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>
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ 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) {
|
|
||||||
|
function createServer(port) {
|
||||||
|
return http.createServer(function(request, response) {
|
||||||
var uri = url.parse(request.url).pathname,
|
var uri = url.parse(request.url).pathname,
|
||||||
filename = path.join(process.cwd(), "../" + uri);
|
filename = path.join(process.cwd(), "../" + uri);
|
||||||
|
|
||||||
@ -40,20 +41,41 @@ var server = http.createServer(function(request, response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}).listen(port);
|
}).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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
var browserDone = function() {
|
||||||
|
if (++browsersDone >= browsers.length) {
|
||||||
server.close();
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(page, result);
|
|
||||||
});
|
|
||||||
})(pages.shift());
|
|
||||||
|
|
||||||
})(["overflow.html", "forms.html", "lists.html"]);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
walkDir("cases", function(err, results) {
|
||||||
|
if (err) throw err;
|
||||||
|
runBrowsers(results);
|
||||||
|
});
|
||||||
|
|
||||||
|
@ -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];
|
||||||
|
Loading…
Reference in New Issue
Block a user