2016-01-15 23:34:28 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var https = require('https');
|
|
|
|
|
|
|
|
function loadJson(url) {
|
|
|
|
let promise = new Promise((resolve, reject) => {
|
|
|
|
https.get(url, function(res){
|
|
|
|
var body = '';
|
|
|
|
|
|
|
|
res.on('data', function(chunk){
|
|
|
|
body += chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
res.on('end', function(){
|
|
|
|
let resp = JSON.parse(body);
|
|
|
|
resolve(resp);
|
|
|
|
});
|
|
|
|
}).on('error', function(e){
|
|
|
|
reject(e);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
2016-01-16 00:22:11 +03:00
|
|
|
const LogLevel = {
|
|
|
|
INFO: 800,
|
|
|
|
WARNING: 900
|
|
|
|
};
|
2016-01-15 23:34:28 +03:00
|
|
|
|
2016-01-16 00:22:11 +03:00
|
|
|
const MAX_ERROR_MESSAGE_SYMBOLS = 128;
|
2016-01-15 23:34:28 +03:00
|
|
|
//copied from angular/modules/angular2/src/testing/e2e_util.ts
|
|
|
|
function verifyNoBrowserErrors() {
|
|
|
|
// Bug in ChromeDriver: Need to execute at least one command
|
|
|
|
// so that the browser logs can be read out!
|
|
|
|
browser.executeScript('1+1');
|
|
|
|
browser.manage().logs().get('browser').then(function(browserLog) {
|
2016-01-16 00:22:11 +03:00
|
|
|
let filteredLog = browserLog.filter((logEntry) => {
|
|
|
|
if (logEntry.level.value >= LogLevel.INFO) {
|
|
|
|
let message = logEntry.message;
|
|
|
|
if (message.length > MAX_ERROR_MESSAGE_SYMBOLS) {
|
|
|
|
message = message.substr(0, MAX_ERROR_MESSAGE_SYMBOLS) + '...';
|
|
|
|
}
|
|
|
|
console.log('>> ' + message);
|
2016-01-15 23:34:28 +03:00
|
|
|
}
|
2016-01-16 00:22:11 +03:00
|
|
|
return logEntry.level.value > LogLevel.WARNING;
|
2016-01-15 23:34:28 +03:00
|
|
|
});
|
2016-01-16 00:22:11 +03:00
|
|
|
expect(filteredLog.length).toEqual(0, `Found ${filteredLog.length} browser errors`);
|
2016-01-15 23:34:28 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToEl(selector) {
|
|
|
|
let script = `
|
|
|
|
document.querySelector('${selector}').scrollIntoView(true);
|
|
|
|
window.scrollBy(0, 10);
|
|
|
|
`;
|
|
|
|
|
|
|
|
return browser.driver.executeScript(script);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
loadJson: loadJson,
|
|
|
|
verifyNoBrowserErrors: verifyNoBrowserErrors,
|
|
|
|
scrollToEl: scrollToEl
|
|
|
|
}
|