chirag04/mail-listener2

The actual email subject in my test case is always the same

Opened this issue · 0 comments

I've config the mail-listener2 on my Node.JS in order to verify when
automatically email is sent to the user during an automation testing I do by Protractor.

In the first test case the verification of the incoming email subject is good,
but in another test cases is always compare the expected subject result to the first test cases and than they are failed.

BTW, I'm pretty sure that the correct email is sent, I saw it in the log,
probably the problem, is because the variables of "email" "subject" I can't find where they come from..

Please your help!

Thanks!

This is the protractor conf file:

var path = require('path');
var fs = require('fs');
var HtmlReporter = require('protractor-html-screenshot-reporter');
var Imap = require('imap'),
    inspect = require('util').inspect;
var MailParser = require("mailparser").MailParser;
var MailListener = require("mail-listener2");



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

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



  onPrepare: function() {
    // here goes your email connection configuration
    var mailListener = new MailListener({
        username: "myemail@gmail.com",
        password: "password",
        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("imapConnected");
    });

    mailListener.on("server:disconnected", function(){
      console.log("imapDisconnected");
    });

    mailListener.on("mail", function(){
      console.log("GO IT!");
    });

    mailListener.on("mail", function(mail, seqno, attributes){
    // do something with mail object including attachments
      console.log("emailParsed", mail);
      // mail processing code goes here
    });

    global.mailListener = mailListener;
}, 

  jasmineNodeOpts: {
      onComplete: function () {
      mailListener.stop();
    },
      // If true, display spec names.
      isVerbose: true,
      // If true, print colors to the terminal.
      showColors: true,
      // If true, include stack traces in failures.
      includeStackTrace: true,
      // Default time to wait in ms before a test fails.
      defaultTimeoutInterval: 9999999
  }

}

This is the failed test case:

describe('LiveSite Portal - Client book a new meeting', function() {

    var randomDay = Math.floor(30*Math.random() + 1);
    var randomDayLink = randomDay.toString(); 
    var EC = protractor.ExpectedConditions;

  it('LiveSite - Home Page', function() {
       liveSiteHome();
    });


  it('Client LiveSite Portal - Schedule new meeting > Services screen', function() { 
    element(by.xpath("//div[@class='actions-row']//a[.='Schedule Now']")).click();
    browser.wait(EC.visibilityOf(element(by.css("div.service-info"))), 15000);
    expect (element(by.css("div.service-info")).isPresent()).toBe(true);
    });

  it('Client LiveSite Portal - New Meeting - Multistaff selection screen', function() {  
    element(by.css("div.service-info")).click();
    browser.wait(EC.visibilityOf(element(by.css("ul.staff"))), 15000);
    expect (element(by.css("ul.staff")).isPresent()).toBe(true);
   });

  it('Client LiveSite Portal - New Meeting - Date picker', function() {  
    element(by.css("ul.staff")).click();
    browser.wait(EC.visibilityOf(element(by.css(".slots"))), 15000);
    expect(element(by.css(".slots")).isPresent()).toBe(true);
  });

  it('Client LiveSite Portal - New Meeting - Booking meeting', function() {  
    element(by.linkText("Next")).click();
    browser.driver.sleep(5000);
    element(by.linkText(randomDayLink)).click();
    browser.wait(EC.visibilityOf(element(by.xpath("//ul[@class='column-2']/li[2]/a/div"))), 15000);
    element(by.xpath("//ul[@class='column-2']/li[2]/a/div")).click();
    browser.wait(EC.visibilityOf(element(by.linkText("Continue"))), 15000);
    element(by.linkText("Continue")).click();
    browser.wait(EC.visibilityOf(element(by.model("meeting[field.attribute_name]"))), 15000);
    expect(element(by.model("meeting[field.attribute_name]")).isPresent()).toBe(true);
 });

  it('Client LiveSite Portal - New Meeting - Client Info', function() {   
    element(by.id("client_phone")) .sendKeys("0556783242")    
    element(by.name("email")).sendKeys("idanvcita@gmail.com");
    element(by.id("terms_of_service")).click();
    element(by.xpath("(//textarea[@id='agenda'])[2]")).sendKeys("hello again");
    element(by.linkText("Submit")).click();
    browser.wait(EC.visibilityOf(element(by.css("a.standard-button"))), 15000);
    expect (element(by.css("a.standard-button")).isPresent()).toBe(true);
  });

  it('Client LiveSite Portal - New Meeting - Email has been sent to the business side', function() {
    browser.driver.controlFlow().await(getLastEmail()).then(function (email) {
      expect(email.subject).toContain("Appointment scheduled with");
    });
  });

  it('Client LiveSite Portal - New Meeting - Appointmend has been scheduled', function() {   
    element(by.linkText("Done")).click();
    waitPageToLoad();
    expect(element(by.model("email")).isPresent()).toBe(true);
  });

});

This is the error:

Error: Expected 'New document shared by vCita idan' to contain 'Appointment scheduled with'. at new jasmine.ExpectationResult (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:137:32) at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1349:29) at [object Object].toContain (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:248:11) at c:\automation\tests\meeting.js:54:29 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.Callback_.goog.defineClass.notify (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25) at [object Object].promise.Promise.notify_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12) at Array.forEach (native) at Object.goog.array.forEach (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43) at [object Object].promise.Promise.notifyAll_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16)