How can i click on a link in email through Protractor code

Viewed 33

I am using protractor-cucmber frame work.I need to test Forgot password scenario. so when i am clicking on forgot password,it will ask for emailid and will get a link in that email.I need to click on that link.For that i have tried with mail-listener4 and added it in the config file as given below.

onPrepare: function() {
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
var MailListener = require("mail-listener4");
// here goes your email connection configuration
var mailListener = new MailListener({
    username: "rosemol.davis@cloudium.io",
    password: "Csoft123!",
    host: "cmail.cloudium.io",
    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");
});
global.mailListener= mailListener;
}

and in the basedefenition.js file added as given below

When(/^I get email content$/, function () {

function getLastEmail() {
  var deferred = protractor.promise.defer();
  console.log("Waiting for an email...");

  mailListener.on("mail", function(mail){
    console.log("emailParsed", mail);
    console.log("mailon");
      deferred.fulfill(mail);
  });
  
  return deferred.promise;
};


browser.wait(getLastEmail()).then(function (email) {
  console.log("email","%%%%%%%%%%%%%%%%%");
  console.log(email);
  console.log(email.text,"###########################@@@@@@");

 });

}); 

But when i am executing this code i can see only the text 'Mail listener initialized' and 'Waiting for an email...' in the command prompt. i think mailListener.on("mail", function(mail){} part is not executing, console.log given under this section is not working.I have tried with both mail-listener4 and mail-listener2, both are giving same result. where i am going wrong? How can i fix this or how can i access the link in the email? Thanks in advance.

0 Answers
Related