【发布时间】:2018-02-01 12:30:11
【问题描述】:
我正在使用以下 mailListner 库进行 E2E Protractor 测试,并且还基于来自这个看起来相当不错的 posting 的信息。
我面临的问题是关于函数getLastEmail():
import { mailListener } from 'mail-listener2';
function getLastEmail() {
const deferred = protractor.promise.defer();
console.log("Waiting for an email...");
mailListener.on("mail", function(mail){
deferred.fulfill(mail);
});
return deferred.promise;
}
当我运行测试时,我不断收到错误消息:
- Failed: Cannot read property 'on' of undefined
看起来 mailListner 未定义。
这里是函数被调用的部分:
describe('sales App', () => {
it('Should send confirmation email', () => {
browser.controlFlow().wait(getLastEmail())
.then((email) => {
expect(email['subject']).toEqual("Confirm Registration");
expect(email['headers'].to).toEqual("firstName@yyy.com");
const pattern = /Registration code is: (\w+)/g;
const regCode = pattern.exec(email['text'])[1];
console.log(regCode);
});
});
});
protractor.confi.js:
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
var MailListener = require("mail-listener2");
// here goes your email connection configuration
var mailListener = new MailListener({
username: "myEmail@yyyy.com",
password: "MyPassword",
host: "imap.gmail.com",
port: 993, // imap port
tls: true,
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX", // mailbox to monitor
searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved
markSeen: true, // all fetched email willbe marked as seen and not fetched next time
fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
mailParserOptions: { streamAttachments: true }, // options to be passed to mailParser lib.
attachments: true, // download attachments as they are encountered to the project directory
attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
});
mailListener.start()
mailListener.on("server:connected", function() {
console.log("Mail listener initialized")
})
mailListener.on("error", function(err) {
console.log(err)
})
mailListener.on("server:disconnected", function() {
console.log("imapDisconnected")
})
global.mailListener = mailListener
},
onCleanUp: function() {
mailListener.stop()
}
知道如何解决和修复它吗?
【问题讨论】:
标签: javascript email protractor e2e-testing