mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[functional testing] Use grunt-run with selenium
This commit is contained in:
parent
a47725ab91
commit
ca81d4b777
6 changed files with 59 additions and 49 deletions
|
@ -140,7 +140,7 @@
|
|||
"grunt-contrib-copy": "0.8.1",
|
||||
"grunt-esvm": "1.1.5",
|
||||
"grunt-karma": "0.12.0",
|
||||
"grunt-run": "0.4.0",
|
||||
"grunt-run": "0.5.0",
|
||||
"grunt-s3": "0.2.0-alpha.3",
|
||||
"grunt-simple-mocha": "0.4.0",
|
||||
"gruntify-eslint": "1.0.1",
|
||||
|
|
|
@ -74,6 +74,34 @@ module.exports = function (grunt) {
|
|||
]
|
||||
},
|
||||
|
||||
seleniumServer: {
|
||||
options: {
|
||||
wait: false,
|
||||
ready: /Selenium Server is up and running/,
|
||||
quiet: true,
|
||||
failOnError: false
|
||||
},
|
||||
cmd: 'java',
|
||||
args: [
|
||||
'-jar',
|
||||
'selenium/selenium-server-standalone-2.47.1.jar'
|
||||
]
|
||||
},
|
||||
|
||||
devSeleniumServer: {
|
||||
options: {
|
||||
wait: false,
|
||||
ready: /Selenium Server is up and running/,
|
||||
quiet: false,
|
||||
failOnError: false
|
||||
},
|
||||
cmd: 'java',
|
||||
args: [
|
||||
'-jar',
|
||||
'selenium/selenium-server-standalone-2.47.1.jar'
|
||||
]
|
||||
},
|
||||
|
||||
optimizeBuild: {
|
||||
options: {
|
||||
wait: false,
|
||||
|
|
|
@ -7,67 +7,50 @@ var crypto = require('crypto');
|
|||
var {spawn} = require('child_process');
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('startSelenium', 'Start an instance of selenium standalone', function (keepalive) {
|
||||
grunt.registerTask('downloadSelenium', 'Download selenium standalone', function (keepalive) {
|
||||
const done = this.async();
|
||||
const config = this.options();
|
||||
|
||||
const SELENIUM_FILE_PATH = path.join(config.selenium.directory, config.selenium.filename);
|
||||
const SELENIUM_DOWNLOAD_URL = config.selenium.server + config.selenium.filename;
|
||||
|
||||
function waitForReadiness(seleniumProcess) {
|
||||
seleniumProcess.stderr.on('data', function (log) {
|
||||
if (~log.toString('utf8').indexOf('Selenium Server is up and running')) {
|
||||
grunt.log.writeln('Selenium standalone started on port 4444');
|
||||
if (keepalive !== 'keepalive') done();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function validateDownload(path, expectedHash, success) {
|
||||
grunt.log.write('Validating hash...');
|
||||
fs.readFile(path, function (err, data) {
|
||||
fs.readFile(path, function checkHash(err, data) {
|
||||
if (err) grunt.fail.warn(err);
|
||||
|
||||
const calculatedHash = crypto.createHash('md5').update(data).digest('hex');
|
||||
if (calculatedHash !== expectedHash) return grunt.fail.warn('Selenium download has an invalid hash');
|
||||
|
||||
grunt.log.writeln('done');
|
||||
success();
|
||||
});
|
||||
}
|
||||
|
||||
function spawnSelenium() {
|
||||
var seleniumProcess = spawn('java', ['-jar', SELENIUM_FILE_PATH]);
|
||||
process.on('exit', function () {
|
||||
seleniumProcess.kill();
|
||||
});
|
||||
waitForReadiness(seleniumProcess);
|
||||
}
|
||||
|
||||
function downloadSelenium(success) {
|
||||
grunt.log.write(`Downloading ${SELENIUM_DOWNLOAD_URL}...`);
|
||||
request.get(SELENIUM_DOWNLOAD_URL)
|
||||
.pipe(fs.createWriteStream(SELENIUM_FILE_PATH))
|
||||
.on('finish', function () {
|
||||
.on('error', function downloadError(err) {
|
||||
grunt.fail.warn(err);
|
||||
})
|
||||
.on('finish', function downloadFinish() {
|
||||
grunt.log.writeln('done');
|
||||
validateDownload(SELENIUM_FILE_PATH, config.selenium.md5, success);
|
||||
})
|
||||
.on('error', function (err) {
|
||||
grunt.fail.warn(err);
|
||||
});
|
||||
}
|
||||
|
||||
function start() {
|
||||
try {
|
||||
fs.mkdirSync(config.selenium.directory);
|
||||
|
||||
} catch (err) {
|
||||
if (err && err.code !== 'EEXIST') grunt.fail.warn(err);
|
||||
}
|
||||
|
||||
if (fs.existsSync(SELENIUM_FILE_PATH)) {
|
||||
spawnSelenium();
|
||||
done();
|
||||
} else {
|
||||
downloadSelenium(spawnSelenium);
|
||||
downloadSelenium(done);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,26 +8,23 @@ module.exports = function (grunt) {
|
|||
grunt.registerTask('loadFixtures', 'Loads fixtures into elasticsearch', function () {
|
||||
const config = this.options();
|
||||
const done = this.async();
|
||||
const files = fs.readdirSync(config.dataDir);
|
||||
let doneProcessing = 0;
|
||||
|
||||
fs.readdir(config.dataDir, function (err, files) {
|
||||
if (err) grunt.fail.warn(err);
|
||||
|
||||
let doneProcessing = 0;
|
||||
files.forEach(function (file) {
|
||||
wreck.post(`${config.server}/_bulk`, {
|
||||
payload: fs.createReadStream(path.join(config.dataDir, file)),
|
||||
json: true
|
||||
}, function (err, res, payload) {
|
||||
var status;
|
||||
if (err || res.statusCode !== 200) {
|
||||
grunt.fail.warn(err || payload);
|
||||
status = colors.red('error');
|
||||
} else {
|
||||
status = colors.green('success');
|
||||
}
|
||||
grunt.log.writeln(`[${status}] ${file}`);
|
||||
if (++doneProcessing === files.length) done();
|
||||
});
|
||||
files.forEach(function (file) {
|
||||
wreck.post(`${config.server}/_bulk`, {
|
||||
payload: fs.createReadStream(path.join(config.dataDir, file)),
|
||||
json: true
|
||||
}, function bulkResponse(err, res, payload) {
|
||||
var status;
|
||||
if (err || res.statusCode !== 200) {
|
||||
grunt.fail.warn(err || payload);
|
||||
status = colors.red('error');
|
||||
} else {
|
||||
status = colors.green('success');
|
||||
}
|
||||
grunt.log.writeln(`[${status}] ${file}`);
|
||||
if (++doneProcessing === files.length) done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,8 +18,9 @@ module.exports = function (grunt) {
|
|||
grunt.registerTask('test:ui', [
|
||||
'esvm:ui',
|
||||
'loadFixtures',
|
||||
'startSelenium',
|
||||
'run:testUIServer',
|
||||
'downloadSelenium',
|
||||
'run:seleniumServer',
|
||||
'intern:dev'
|
||||
]);
|
||||
|
||||
|
@ -27,7 +28,8 @@ module.exports = function (grunt) {
|
|||
'esvm:ui',
|
||||
'loadFixtures',
|
||||
'run:testUIServer',
|
||||
'startSelenium:keepalive'
|
||||
'downloadSelenium',
|
||||
'run:devSeleniumServer:keepalive'
|
||||
]);
|
||||
|
||||
grunt.registerTask('test:ui:runner', [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue