0

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

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

这是我的代码的样子。出于安全目的,我跳过了登录和打开站点部分。所有这部分工作正常。代码挂在 test.wait(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);
});

感谢您在高级方面的帮助!

4

1 回答 1

0

详细说明我的评论:也许您必须等待您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);
  }
};
于 2016-01-04T20:42:43.707 回答