在成功执行测试后,如何通过电子邮件将“protractor-jasmine2-html-reporter”生成的报告发送给利益相关者。

时间:2018-03-07 18:27:01

标签: email jasmine protractor report

我有一个配置文件如下:

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');

exports.config = {  
directConnect: true,

onPrepare: function() {
  jasmine.getEnv().addReporter(
    new Jasmine2HtmlReporter({
      savePath: './test/reports/',
      screenshotsFolder: 'images',
    })
  );
},

multiCapabilities: [
                   {
                     'browserName': 'chrome',
                   }],

framework: 'jasmine',



specs: ['zoo_spec.js'],


jasmineNodeOpts: {
showColors: true,  
defaultTimeoutInterval: 30000
                 }  
};

我的问题是,我可以编写任何代码,以便在测试执行完成后立即发送从jasmine2-html-reporter生成的报告。

3 个答案:

答案 0 :(得分:0)

在配置onComplete:function(){}中,您可以编写自定义代码来发送电子邮件。有许多nodejs电子邮件客户端可以重复使用,无需重新发送即可发送电子邮件。以下是您可以使用https://nodemailer.com/about/的示例客户端,还可以查看SMTP部分以进行配置;

答案 1 :(得分:0)

按照你的说法试试。现在我的conf.js如下所示:

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var q = require('q');
var fs = require('fs');
var nodemailer=require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var SendMail = function () {
    this.sendHTMLMail = function (htmlContent) {        
        var transporter = nodemailer.createTransport(smtpTransport({
              service: 'Gmail',
              host: 'smtp.gmail.com',
              auth: {
                user: 'xxx@gmail.com',
                pass: 'xxx',
              }
            }));
        var mailOptions = {
            from: 'xxx@gmail.com',
            to: 'yyy@yahoo.in', 
            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);
        });
    };
};

exports.config = {
  //seleniumAddress: 'http://localhost:4444/wd/hub',    
  directConnect: true,

  onPrepare: function() {
      jasmine.getEnv().addReporter(
        new Jasmine2HtmlReporter({
          savePath: './test/reports/',
          screenshotsFolder: 'images',
        })
      );
   },

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

        //  Send HTML Email
        var htmlFilePath = 'test\\reports\\htmlReport.html';
        var htmlFileContent = String(fs.readFileSync(htmlFilePath));
        (new SendMail).sendHTMLMail(htmlFileContent);
       }).delay(1000);
    },

  // Capabilities to be passed to the webdriver instance.
   multiCapabilities: [
                       {
                         'browserName': 'chrome',
                       }],
  // Framework to use. Jasmine is recommended.
  framework: 'jasmine',


  // Spec patterns are relative to the current working directory when
  // protractor is called.
  specs: ['zoo_spec.js'],

  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    showColors: true,  
    defaultTimeoutInterval: 30000
  }
};

代码不会返回任何错误。不调用transporter.sendMail函数。我不明白为什么。

答案 2 :(得分:0)

您是否尝试使用 onComplete ?请参考下面的上一个答案

Unable to send Email using nodemailer in protractor.conf.js onComplete: function()