cryptpad/TestSelenium.js

79 lines
2.8 KiB
JavaScript
Raw Normal View History

/* global process */
var WebDriver = require("selenium-webdriver");
2017-05-31 17:40:17 +00:00
var nThen = require('nthen');
if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false') {
// We can't do saucelabs on pull requests so don't fail.
return;
}
var driver;
if (process.env.SAUCE_USERNAME !== undefined) {
var browserArray = process.env.BROWSER.split(':');
driver = new WebDriver.Builder().usingServer(
'http://'+ process.env.SAUCE_USERNAME+':'+process.env.SAUCE_ACCESS_KEY+'@ondemand.saucelabs.com:80/wd/hub'
).withCapabilities({
"tunnel-identifier": process.env.TRAVIS_JOB_NUMBER,
"build": process.env.TRAVIS_JOB_NUMBER,
"username": process.env.SAUCE_USERNAME,
"accessKey": process.env.SAUCE_ACCESS_KEY,
}).forBrowser(browserArray[0], browserArray[1], browserArray[2]).build();
} else {
driver = new WebDriver.Builder().withCapabilities({ browserName: "chrome" }).build();
}
var SC_GET_DATA = "return (window.__CRYPTPAD_TEST__) ? window.__CRYPTPAD_TEST__.getData() : '[]'";
var failed = false;
2017-05-31 17:40:17 +00:00
var nt = nThen;
[
'/assert/#?test=test',
2017-05-31 22:41:31 +00:00
// '/auth/#?test=test' // TODO(cjd): Not working on automatic tests, understand why.
2017-05-31 17:40:17 +00:00
].forEach(function (path) {
if (failed) { return; }
2017-05-31 17:40:17 +00:00
var url = 'http://localhost:3000' + path;
nt = nt(function (waitFor) {
var done = waitFor();
console.log('\n\n-----TEST ' + url + ' -----');
2017-05-31 17:40:17 +00:00
driver.get(url);
var waitTo = setTimeout(function () {
console.log("no report in 20 seconds, timing out");
failed = true;
done();
done = undefined;
}, 20000);
var logMore = function () {
if (!done) { return; }
driver.executeScript(SC_GET_DATA).then(waitFor(function (dataS) {
var data = JSON.parse(dataS);
data.forEach(function (d) {
if (d.type !== 'log') { return; }
console.log('>' + d.val);
});
data.forEach(function (d) {
if (d.type !== 'report') { return; }
console.log('RESULT: ' + d.val);
if (d.val !== 'passed') {
if (d.error) {
console.log(d.error.message);
console.log(d.error.stack);
}
failed = true;
}
clearTimeout(waitTo);
console.log('-----END TEST ' + url + ' -----');
done();
done = undefined;
});
if (done) { setTimeout(logMore, 50); }
}));
};
logMore();
2017-05-31 17:40:17 +00:00
}).nThen;
});
2017-05-31 17:40:17 +00:00
nt(function (waitFor) {
driver.quit().then(waitFor(function () {
if (failed) { process.exit(100); }
}));
2017-05-31 21:32:47 +00:00
});