Dalekjs和运行Nodejs函数



我正在编写运行测试的代码,如果结果以某种方式返回,我想给自己发一封电子邮件。

不幸的是,每次DalekJS运行我的代码时,它似乎都跳过了电子邮件功能。

以下是我的代码。出于安全考虑,我跳过了登录和打开网站的部分。所有这部分都很好。代码挂起测试。等待(15000)。

这是所需代码var emailjs = require('./seeifemail');

test.click('#header_navbar_account_landers')
test.wait(15000)
test.execute(function() {
    if ($('#select2-chosen-6').text() != "United States of America") {
      $('#select2-chosen-6').text("United States of America")
      $('#select2-chosen-6').change()
    }
    })
    var msgCnt = parseInt($('.loaded-total').text(), 10);
    if (msgCnt > 0) {
      emailjs.magicFn
      return 'done'
    } else {
      alert('it didn't work')
      return 'done'
    }
  test.wait(20000)
  test.done();

以下是seeifemail的样子。

var email = require('emailjs/email');
var server = email.server.connect({
user: "username",
password: "password",
host: "smtp.gmail.com",
ssl: true
});
 module.exports = {
 magicFn: function() {

server.send({
  text: "i hope this works",
  from: "you <username@your-email.com>",
  to: "email@email.com",
  cc: "else <else@your-email.com>",
  subject: "testing emailjs"
}, function(err, message) {
  console.log(err || message);
});

提前感谢您的帮助!

详述我的评论:也许你必须等待你的server.send()完成,然后才能return,从而(可能)终止你的应用程序:

test.click('#header_navbar_account_landers');
test.wait(15000);
test.execute(function() {
  if ($('#select2-chosen-6').text() != "United States of America") {
    $('#select2-chosen-6').text("United States of America");
    $('#select2-chosen-6').change();
  }
});
var msgCnt = parseInt($('.loaded-total').text(), 10);
if (msgCnt > 0) {
  emailjs.magicFn(function(err, message) {
    return 'done';
  });
} else {
  alert('it didn't work');
  return 'done';
}
test.wait(20000);
test.done();

然后:

var email = require('emailjs/email');
var server = email.server.connect({
  user: "username",
  password: "password",
  host: "smtp.gmail.com",
  ssl: true
});
module.exports = {
  magicFn: function(callback) {
    server.send({
      text: "i hope this works",
      from: "you <username@your-email.com>",
      to: "email@email.com",
      cc: "else <else@your-email.com>",
      subject: "testing emailjs"
    }, callback);
  }
};

相关内容

  • 没有找到相关文章

最新更新