Link to information from the question Getting Values from Email in the Protractor Test Example , I still cannot link to emails. In my test case, the “wait” fails for some unknown reason.
Also, if I use a string,
browser.controlFlow().await(getLastEmail()).then(...)
There is "browser.controlFlow (...). Await is not a function error"
conf.js
var MailListener = require("mail-listener2")
exports.config = {
framework: 'jasmine2',
specs: ['./test.js'],
jasmineNodeOpts: { defaultTimeoutInterval: 360000 },
allScriptsTimeout: 60000,
onPrepare: function () {
var mailListener = new MailListener({
username: "username",
password: "password",
host: "imapPort",
port: 993,
secure: true,
tls: true,
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX",
searchFilter: ["UNSEEN", "FLAGGED"],
markSeen: true,
fetchUnreadOnStart: true,
mailParserOptions: {streamAttachments: true},
attachments: true,
attachmentOptions: { directory: "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()
}
}
Test case:
describe('Email Testing', function () {
it('should login with a registration code sent to an email', function () {
getLastEmail().then(function (email) {
expect(email.subject).toEqual('My Subject')
})
})
})
function getLastEmail () {
var deferred = protractor.promise.defer()
console.log('Waiting for an email...')
mailListener.on('mail', function (mail) {
console.log('No Console Log Here!')
deferred.fulfill(mail)
})
return deferred.promise
}
I'm not sure what I am missing in my test case to read the subject or body of the letter?