mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Refactor webdriver test running
This commit is contained in:
parent
e7d8644c05
commit
017e68ec37
@ -129,11 +129,11 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask('webdriver', 'Browser render tests', function() {
|
grunt.registerTask('webdriver', 'Browser render tests', function(browser, test) {
|
||||||
var selenium = require("./tests/selenium.js");
|
var selenium = require("./tests/selenium.js");
|
||||||
var done = this.async();
|
var done = this.async();
|
||||||
var browsers = (this.args.length) ? [grunt.config.get(this.nameArgs.replace(":", "."))] : _.values(grunt.config.get(this.name));
|
var browsers = (browser) ? [grunt.config.get(this.name + "." + browser)] : _.values(grunt.config.get(this.name));
|
||||||
selenium.tests(browsers).onValue(done);
|
selenium.tests(browsers, test).onValue(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load tasks
|
// Load tasks
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"baconjs": "0.7.11",
|
"baconjs": "0.7.11",
|
||||||
"base64-arraybuffer": ">= 0.1.0",
|
"base64-arraybuffer": ">= 0.1.0",
|
||||||
"grunt": ">=0.4.0",
|
"grunt": "^0.4.5",
|
||||||
"grunt-contrib-concat": "*",
|
"grunt-contrib-concat": "*",
|
||||||
"grunt-contrib-connect": "0.7.1",
|
"grunt-contrib-connect": "0.7.1",
|
||||||
"grunt-contrib-jshint": "*",
|
"grunt-contrib-jshint": "*",
|
||||||
|
@ -127,39 +127,44 @@
|
|||||||
var browserStream = new Bacon.Bus();
|
var browserStream = new Bacon.Bus();
|
||||||
if (process.env.TRAVIS_JOB_NUMBER) {
|
if (process.env.TRAVIS_JOB_NUMBER) {
|
||||||
test.capabilities["tunnel-identifier"] = process.env.TRAVIS_JOB_NUMBER;
|
test.capabilities["tunnel-identifier"] = process.env.TRAVIS_JOB_NUMBER;
|
||||||
test.capabilities["name"] = process.env.TRAVIS_COMMIT.substring(0, 10) + " #" + process.env.TRAVIS_BUILD_NUMBER;
|
test.capabilities["name"] = process.env.TRAVIS_COMMIT.substring(0, 10);
|
||||||
|
test.capabilities["build"] = process.env.TRAVIS_BUILD_NUMBER;
|
||||||
|
} else {
|
||||||
|
test.capabilities["name"] = "Manual run";
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultStream = Bacon.fromNodeCallback(browser, "init", test.capabilities)
|
var resultStream = Bacon.fromNodeCallback(browser, "init", test.capabilities)
|
||||||
.flatMap(Bacon.fromNodeCallback(browser, "setImplicitWaitTimeout", 15000)
|
.flatMap(Bacon.fromNodeCallback(browser, "setImplicitWaitTimeout", 15000)
|
||||||
.flatMap(function() {
|
.flatMap(function() {
|
||||||
Bacon.later(0, formatResultName(test.capabilities)).onValue(browserStream.push);
|
Bacon.later(0, formatResultName(test.capabilities)).onValue(browserStream.push);
|
||||||
return Bacon.fromArray(test.cases).zip(browserStream.take(test.cases.length)).flatMap(function(options) {
|
return Bacon.fromArray(test.cases).zip(browserStream.take(test.cases.length)).flatMap(function(options) {
|
||||||
var testCase = options[0];
|
var testCase = options[0];
|
||||||
var name = options[1];
|
var name = options[1];
|
||||||
console.log(colors.green, "STARTING", name, testCase, colors.clear);
|
console.log(colors.green, "STARTING", name, testCase, colors.clear);
|
||||||
return Bacon.fromNodeCallback(browser, "get", "http://localhost:" + port + "/" + testCase + "?selenium")
|
return Bacon.fromNodeCallback(browser, "get", "http://localhost:" + port + "/" + testCase + "?selenium")
|
||||||
.flatMap(Bacon.combineTemplate({
|
.flatMap(Bacon.combineTemplate({
|
||||||
dataUrl: Bacon.fromNodeCallback(browser, "elementByCssSelector", ".html2canvas").flatMap(function(canvas) {
|
dataUrl: Bacon.fromNodeCallback(browser, "elementByCssSelector", ".html2canvas").flatMap(function(canvas) {
|
||||||
return Bacon.fromNodeCallback(browser, "execute", "return arguments[0].toDataURL('image/png').substring(22)", [canvas]);
|
return Bacon.fromNodeCallback(browser, "execute", "return arguments[0].toDataURL('image/png').substring(22)", [canvas]);
|
||||||
}),
|
}),
|
||||||
screenshot: Bacon.fromNodeCallback(browser, "takeScreenshot")
|
screenshot: Bacon.fromNodeCallback(browser, "takeScreenshot")
|
||||||
})).flatMap(function(result) {
|
}))
|
||||||
return Bacon.combineTemplate({
|
.flatMap(function(result) {
|
||||||
browser: name,
|
return Bacon.combineTemplate({
|
||||||
testCase: testCase,
|
browser: name,
|
||||||
accuracy: Bacon.constant(result.dataUrl).flatMap(getPixelArray).combine(Bacon.constant(result.screenshot).flatMap(getPixelArray), calculateDifference),
|
testCase: testCase,
|
||||||
dataUrl: result.dataUrl,
|
accuracy: Bacon.constant(result.dataUrl).flatMap(getPixelArray).combine(Bacon.constant(result.screenshot).flatMap(getPixelArray), calculateDifference),
|
||||||
screenshot: result.screenshot
|
dataUrl: result.dataUrl,
|
||||||
});
|
screenshot: result.screenshot
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
resultStream.onError(function(error) {
|
resultStream.onError(function(error) {
|
||||||
var name = formatResultName(test.capabilities);
|
var name = formatResultName(test.capabilities);
|
||||||
console.log(colors.red, "ERROR", name, error.message);
|
console.log(colors.red, "ERROR", name, error.message);
|
||||||
browserStream.push(name);
|
browserStream.push(name);
|
||||||
|
browser.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
resultStream.onValue(function(result) {
|
resultStream.onValue(function(result) {
|
||||||
@ -207,7 +212,7 @@
|
|||||||
return result.fold([], pushToArray);
|
return result.fold([], pushToArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.tests = function(browsers) {
|
exports.tests = function(browsers, singleTest) {
|
||||||
return getTests("tests/cases").fold([], pushToArray).flatMap(runWebDriver.bind(null, browsers)).mapError(false);
|
return (singleTest ? Bacon.constant([singleTest]) : getTests("tests/cases").fold([], pushToArray)).flatMap(runWebDriver.bind(null, browsers)).mapError(false);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user