我正在编写运行测试的代码,如果结果以某种方式返回,我想向自己发送一封电子邮件。
不幸的是,每次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);
});
感谢您的高级帮助!
答案 0 :(得分: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);
}
};