-1

How to automate the email validation part with automated scripts.

Customer configured his mail as 'test@gmail.com', he/she login to application. Once after every successful login, customer gets a mail to his 'test@gmail' inbox. We created a test gmail account and validating for the same customer but through manual process as usually what we do like as day-to-day. We need some help/suggestion on how to automate this gmail validation part also, like launching gmail, selecting the exact mail after each scenario is done, and validating the body content too most importantly. Please help on this.

Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
mmar
  • 1,840
  • 6
  • 28
  • 41
  • Possible duplicate of [Fetching values from email in protractor test case](https://stackoverflow.com/questions/29311154/fetching-values-from-email-in-protractor-test-case) – Gunderson Feb 08 '19 at 18:48

2 Answers2

0

What I suggest is configuring a tool like https://ngrok.com/ which will allow you to setup an endpoint to receive traffic. Then I would build your software to allow custom endpoints for things such as successful login and you can set that endpoint to b your NGrok endpoint when logged in as the test user.

Ray
  • 1,134
  • 10
  • 27
0

there are many npm ackage you need to check which one will be good for you.

  1. nodemailer
  2. mail- liestner
  3. imap etc..

3rd one I personally preferred just got through this package.

you can also try that:

var quotedPrintable = require('quoted-printable');
var utf8 = require('utf8');

var Imap = require('imap'),
    inspect = require('util').inspect;

var imap = new Imap({
  user: 'xxxxxx@gmail.com',
  password: 'xxxxxxx',
  host: 'imap.gmail.com',
  port: 993,
  tls: true
});

function openMail(cb) {
  imap.openBox("[Gmail]/All Mail", true, cb);
}

imap.once('ready', function() {
    openMail(function(err, box) {
      if (err) throw err;
      for(i = 0; i < n; i++){
        var f = imap.seq.fetch((box.messages.total-i) + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT']});
          f.on('message', function(msg, seqno) {
            ('Message #%d', seqno);
            var prefix = '(#' + seqno + ') ';
            msg.on('body', function(stream, info) {
              var buffer = '', count = 0;
              stream.on('data', function(chunk) {
                count += chunk.length;
                buffer += chunk.toString('utf8');
              });
              stream.once('end', function() {
                if (info.which !== 'TEXT')
                  (prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
                else
                  (prefix + 'Body [%s] Finished', inspect(info.which));

                var bufferPrint = JSON.stringify(quotedPrintable.decode(utf8.decode(buffer)));
              });
            });
          });
      }

      msg.once('attributes', function(attrs) {
        console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
      });
      msg.once('end', function() {
        console.log(prefix + 'Finished');
      });

      f.once('error', function(err) {
        console.log('Fetch error: ' + err);
      });
      f.once('end', function() {
        imap.end();
      });
    });
});

imap.once('error', function(err) {
  console.log(err);
});

imap.once('end', function() {});

imap.connect();
DevArti
  • 38
  • 18