2016-10-14 1 views
1

Knotenmailer sendet keine E-Mail, wenn er in Winkelmesserkonfiguration abgelegt wird afterLaunch() - Block. Er sendet E-Mails, wenn er in den Blöcken beforeLaunch() oder onPrepare() platziert wird.nodemailer sendet keine E-Mails, wenn sie in Winkelmesserkonfiguration abgelegt wird afterLaunch() Block

Problem: Senden Sie HTML-Mail, nachdem der Winkelmesser-Testlauf abgeschlossen ist. Das Framework generiert eine HTML-Datei, sobald die Ausführung abgeschlossen ist. nodemailer den HTML-Inhalt zu lesen und senden E-Mail

config.js

exports.config = { 
    specs: ['../test_lab/execute.spec.js'], 

    capabilities: { 
     browserName: 'chrome', 
     seleniumAddress: 'http://localhost:4444/wd/hub', 
    }, 

    beforeLaunch: function() { 
     // beforeLaunch actions 
    }, 

    onPrepare: function() { 
     // onPrepare actions 
    }, 

    afterLaunch: function() { 
     // generate HTML report 

     // Send HTML Email 
     var htmlFilePath = '../index.html'; 
     var htmlFileContent = String(fs.readFileSync(htmlFilePath)); 
     sendMail.sendHTMLMail(htmlFileContent); 
    }, 

    framework: 'jasmine2', 

    jasmineNodeOpts: { 
     onComplete: null, 
     showColors: true, 
     defaultTimeoutInterval: 60000 
    } 
}; 

nodemailer - Mail senden Helferfunktion

var SendMail = function() { 
    this.sendHTMLMail = function (htmlContent) {   
     var transporter = nodemailer.createTransport('smtps://testmail%40gmail.com:[email protected]'); 
     var mailOptions = { 
      from: '"test mail" <[email protected]>', 
      to: '[email protected]', 
      subject: 'Test Report', 
      text: 'Test Report', 
      html: htmlContent 
     }; 
     transporter.sendMail(mailOptions, function (error, info) { 
      if (error) { 
       return console.log(error); 
      } 
      console.log('Mail sent: ' + info.response); 
     }); 
    }; 
}; 

ich festgestellt, dass der Code den sendHTML Block eintritt, aber transporter.sendMail() wird nicht ausgeführt

Antwort

2

Ich habe ein ähnliches Problem vor.

Try this:

config.js

var q = require('q'); 
exports.config = { 
    specs: ['../test_lab/execute.spec.js'], 

    capabilities: { 
     browserName: 'chrome', 
     seleniumAddress: 'http://localhost:4444/wd/hub', 
    }, 

    beforeLaunch: function() { 
     // beforeLaunch actions 
    }, 

    onPrepare: function() { 
     // onPrepare actions 
    }, 

    afterLaunch: function() { 
     return q.fcall(function() { 
     // generate HTML report 

     // Send HTML Email 
     var htmlFilePath = '../index.html'; 
     var htmlFileContent = String(fs.readFileSync(htmlFilePath)); 
     sendMail.sendHTMLMail(htmlFileContent); 
     }).delay(1000); 
    }, 

    framework: 'jasmine2', 

    jasmineNodeOpts: { 
     onComplete: null, 
     showColors: true, 
     defaultTimeoutInterval: 60000 
    } 
}; 
+1

Perfekt .. Dies funktioniert für mich .. Vielen Dank .. – Debo

Verwandte Themen