From 6260e396b514d9124db5331f4d73b7a22adbe568 Mon Sep 17 00:00:00 2001 From: Freddy Vega Date: Fri, 14 Oct 2016 13:58:32 -0400 Subject: [PATCH] enhanced execution email --- app.js | 4 +- public/login.html | 10 +- routes/executionengine.js | 324 +++++++++++++++++++++++++++++++------- 3 files changed, 275 insertions(+), 63 deletions(-) diff --git a/app.js b/app.js index 7a443351..c3b1fd9e 100644 --- a/app.js +++ b/app.js @@ -148,7 +148,9 @@ app.post('/record/recorded',recorder.recorded); //screenshots app.post('/screenshots',screenshots.Post); -app.get('/screenshots/:id',auth.auth,screenshots.Get); +//app.get('/screenshots/:id',auth.auth,screenshots.Get); +app.get('/screenshots/:id',screenshots.Get); + app.get('/',auth.auth, routes.index); app.get('/index.html',auth.auth,function(req,res){res.sendfile(__dirname+'/index.html');}); diff --git a/public/login.html b/public/login.html index af50f822..95622930 100644 --- a/public/login.html +++ b/public/login.html @@ -16,14 +16,14 @@
- RedwoodHQ logo + Wolters Kluwer logo
-
+

 
Download Agent

 
-
Default credentials are: admin/admin
-
Version 2.4.12
+
UpToDate's Automation Platform for Web, API, Mobile and Performance testing
+
Version 2.4.13
- + \ No newline at end of file diff --git a/routes/executionengine.js b/routes/executionengine.js index ab91acbc..2f88c6b1 100644 --- a/routes/executionengine.js +++ b/routes/executionengine.js @@ -115,7 +115,8 @@ var _startexecutionPost = function(req, res, callback){ var variables = {}; var testcases = req.body.testcases; var template = null; - + var emails = req.body.emails; + console.log(req.body); //clean up previous files if needed /* for(var file in fileSync){ @@ -172,8 +173,8 @@ var _startexecutionPost = function(req, res, callback){ if(req.body.templates){ template = req.body.templates[0] } - - executions[executionID] = {template:template,sendEmail:sendEmail,ignoreAfterState:ignoreAfterState,ignoreStatus:ignoreStatus,ignoreScreenshots:ignoreScreenshots,allScreenshots:allScreenshots,testcases:{},machines:machines,variables:variables,currentTestCases:{},project:req.cookies.project,username:req.cookies.username,returnVars:{}}; + executions[executionID] = {template:template,sendEmail:sendEmail,ignoreAfterState:ignoreAfterState,ignoreStatus:ignoreStatus,ignoreScreenshots:ignoreScreenshots,allScreenshots:allScreenshots,testcases:{},machines:machines,variables:variables,currentTestCases:{},project:req.cookies.project,username:req.cookies.username,returnVars:{}, + emails:emails}; updateExecution({_id:executionID},{$set:{status:"Running",user:req.cookies.username}},false); compileBuild(req.cookies.project,req.cookies.username,function(err){ @@ -626,7 +627,9 @@ function executeTestCases(testcases,executionID){ }); updateExecution({_id:executionID},{$set:{status:"Ready To Run"}},true,function(){ executionsRoute.updateExecutionTotals(executionID,function(){ - if(executions[executionID].sendEmail == true) sendNotification(executionID); + if(executions[executionID].sendEmail == true) { + sendNotification(executionID); + } //git.deleteFiles(path.join(__dirname, '../public/automationscripts/'+executions[executionID].project+"/"+executions[executionID].username+"/build"),os.tmpDir()+"/jar_"+executionID); deleteDir(os.tmpDir()+"/jar_"+executionID); delete executions[executionID]; @@ -664,7 +667,10 @@ function executeTestCases(testcases,executionID){ }); updateExecution({_id:executionID},{$set:{status:"Ready To Run"}},true,function(){ executionsRoute.updateExecutionTotals(executionID,function(){ - if(executions[executionID] && executions[executionID].sendEmail == true) sendNotification(executionID); + if(executions[executionID] && executions[executionID].sendEmail == true) + { + sendNotification(executionID); + } //git.deleteFiles(path.join(__dirname, '../public/automationscripts/'+executions[executionID].project+"/"+executions[executionID].username+"/build"),os.tmpDir()+"/jar_"+executionID); deleteDir(os.tmpDir()+"/jar_"+executionID); delete executions[executionID]; @@ -2611,15 +2617,228 @@ function GetTestCaseDetails(testcaseID,dbID,executionID,callback){ }) }); } +function _generateEmailReport(settings, execution, callback) { + var body = ''; + //settings.serverHost = 'localhost'; // temp + + // 1. "Test Execution Summary:" + function _formTestExecutionSummaryReport() { + if(!execution) return ''; + var str = '

Execution Summary:

' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
Total '+execution.total+ " " +'
Passed '+execution.passed + " "+'
Failed '+execution.failed+ " " +'
Not Run '+execution.notRun + " " + '

'; + + return str; + } + + function _getMachinesAsString() { + if(!execution || !execution.machines || execution.machines.length < 1) return ''; + var str = ''; + for(var i = 0; i < execution.machines.length; i++) { + str += " " + execution.machines[i].host + ':' + execution.machines[i].port + '
'; + } + return str; + } + + // 2. "Execution Details:" + function _formExecutionDetailsReport() { + if(!execution) return ''; + var str = '

Execution Details:

' + + '

' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
User '+execution.user+" "+'
Machines '+_getMachinesAsString()+" "+'
Project '+execution.project+" "+'
Test Suite Name '+execution.testsetname+" "+'

'; + + return str; + } + + // 3. "Execution Variable Details:" + function _formExecutionVariablesDetailsReport() { + if(!execution || !execution.variables || execution.variables.length < 1) return ''; + + var str = '

Execution Variable Details:

' + + '

' + + '' + + '' + + '' + + ''; + for(var i = 0; i < execution.variables.length; i++) { + str += '' + + '' + + '' + + ''; + } + + str += '
Name Value
'+ execution.variables[i].name + " " +''+ execution.variables[i].value + " " +'

'; + return str; + } + function _getParametersAsString(parameters){ + if(!parameters || parameters.length < 1) return ''; + var str = ''; + for(var i = 0; i < parameters.length; i++) { + str += "" + parameters[i].paramname + ' = ' + parameters[i].paramvalue + '
'; + } + return str; + } + + function _prepareTestResultRow(rowData, addOrderColumnData) { + var row = ''; + row += '' + + ''+ function() { return (addOrderColumnData) ? rowData.order : '' }() + '' + + ''+ rowData.name + '' + + ''+ _getParametersAsString(rowData.parameters) +''; + if(rowData.status === 'Finished') { + row += ''+ rowData.status +''; + } else { // Not run + row += ''+ rowData.status +''; + } + if(rowData.result === 'Passed') { + row += ''+ rowData.result +''; + } else if(rowData.result === 'Failed') { + row += ''+ rowData.result +''; + } else { + row += ''; + } + row += ''+ function() { return (rowData.error) ? rowData.error : '' }() +''; + if(rowData.screenshot) { + row += ''+ "view" + ''; + }else { + row += ''; + } + row += ''+ function() { return (rowData.trace) ? rowData.trace : ''}() +'' + + ''; + + return row; + } + + // 4. "TestCase Results:" + function _formTestResultsReport(callbackFunc) { + var str = ''; + // console.log("_formTestResultsReport +1") + db.collection('testcaseresults', function(err, collection) { + // console.log("_formTestResultsReport +2") + collection.find({executionID:execution._id}, {}, function(err, cursor) { + //console.log("_formTestResultsReport +3") + if(!cursor || err) return '

_formTestResultsReport failed

'; + //console.log("_formTestResultsReport +4") + + str += '

Test Case Results:

'; + cursor.each(function(err, testcaseresult) { + //console.log("_formTestResultsReport +5") + if(testcaseresult) { + //console.log("_formTestResultsReport +6") + + str += '

' + '

Name: ' + testcaseresult.name + '
'; + if(testcaseresult.status === 'Finished') { + str += '
Status: ' + testcaseresult.status + '
'; + } else { + str += '
Status: ' + testcaseresult.status + '
'; + } + if(testcaseresult.result === 'Passed') { + str += '
Result: ' + testcaseresult.result + '
'; + } else if(testcaseresult.result === 'Failed') { + str += '
Result: ' + testcaseresult.result + '
'; + } else { + str += '
Result: ' + testcaseresult.result + '
'; + } + str += '

' + + '

' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + if(!err && testcaseresult.children){ // success + //console.log("_formTestResultsReport +7") + console.log(testcaseresult.children); + var rows = ''; + for(var i = 0; i < testcaseresult.children.length; i++) { + //console.log("_formTestResultsReport +8" + i) + rows += _prepareTestResultRow(testcaseresult.children[i], true); + + // attach nested child report + var grandChild = testcaseresult.children[i].children; + if(grandChild) { + for(var j = 0; j < grandChild.length; j++) { + // console.log("_formTestResultsReport GRANDCHILD+8" + j) + rows += _prepareTestResultRow(grandChild[j], false); + } + } + } + str += rows + '
Test StepAction NameParametersStatusResultErrorScreenshotTrace


'; + } + } + // console.log("_formTestResultsReport +9") + }); + }); + }); + + setTimeout(function() { + callbackFunc(str); + }, 500); + } + + var body = "

" + + "Execution: " + execution.name + "

"; + + body = body + _formTestExecutionSummaryReport() + + _formExecutionDetailsReport() + + _formExecutionVariablesDetailsReport(); + + _formTestResultsReport(function(str) { + body += str; + callback(body); + }); +} function sendNotification(executionID){ + // console.log("sendNotification +1"); db.collection('emailsettings', function(err, collection) { + //console.log("sendNotification +2"); db.collection('executions', function(err, EXEcollection) { + //console.log("sendNotification +3"); collection.findOne({}, {}, function(err, settings) { + //console.log("sendNotification +4"); EXEcollection.findOne({_id:executionID}, {}, function(err, execution) { - if(!execution.emails) return; - if(execution.emails.length == 0) return; + //console.log("sendNotification +5"); + if(!execution.emails || execution.emails.length == 0) return; + //console.log("sendNotification +6"); if((settings == null) || (!settings.host) || (settings.host == "")) return; + //console.log("sendNotification +7"); var options = {}; var subject = "Execution FINISHED: " + execution.name; @@ -2628,63 +2847,54 @@ function sendNotification(executionID){ } else{ subject = subject + " (ALL PASSED)" + // Send email notification only when execution failed + //return; } - var body = "

Execution: " + execution.name + "

"; - - body = body + '

' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
Total'+execution.total+'
Passed'+execution.passed+'
Failed'+execution.failed+'
Not Run'+execution.notRun+'

'; - if(settings.user){ - options.auth = {user:settings.user,pass:settings.password} - } - options.host = settings.host; - if((settings.port)&&(settings.port!="")){ - options.port = parseInt(settings.port); - } - else{ - options.port = 25 - } - var smtpTransport = nodemailer.createTransport("SMTP",options); - var toList = ""; - execution.emails.forEach(function(email){ - if(toList == ""){ - toList = email + _generateEmailReport(settings, execution, function(body) { + if(settings.user){ + options.auth = {user:settings.user,pass:settings.password} } - else{ - toList = toList + "," + email + options.host = settings.host; + if((settings.port)&&(settings.port!="")){ + options.port = parseInt(settings.port); } - }); - var mailOptions = { - from: "redwoodhq-no-reply@redwoodhq.com", - to: toList, - subject: subject, - //text: "Hello world", // plaintext body - html: body // html body - }; - - smtpTransport.sendMail(mailOptions, function(error, response){ - if(error){ - common.logger.info(error); + else{ + options.port = 25 } + //console.log("sendNotification +8"); + var smtpTransport = nodemailer.createTransport("SMTP",options); + var toList = ""; + execution.emails.forEach(function(email){ + if(toList == ""){ + toList = email + } + else{ + toList = toList + "," + email + } + }); + var mailOptions = { + from: "redwoodhq-no-reply@redwoodhq.com", + to: toList, + subject: subject, + //text: "Hello world", // plaintext body + html: body // html body + }; + + smtpTransport.sendMail(mailOptions, function(error, response){ + //console.log("sendNotification +9"); + if(error){ + common.logger.info(error); + console.log(error); + // console.log("sendNotification +10"); + } - smtpTransport.close(); + smtpTransport.close(); + }); + //console.log("sendNotification end +100"); + console.log(body); }); + }); }); })