Reading Gmail from Protractor
<p>I have a protractor test that uses mailinator for check if I am receiving some mails but I would like to use Gmail instead.</p>

<p>My test looks like this:</p>

<p>In my down-mail.js:</p>

<pre><code>function findEmailBySubject(subject) {

console.log("searching");
var emails = element.all(by.repeater('email in emails')).all(by.binding('email.subject'));

var theOne;

emails.map(function (item) {
    return item.getText();
}).then(function (names) {
    for (var i = 0; i &lt; names.length; i++) {
        console.log(names[i]);
        //console.log(theOne);
        if (names[i].indexOf(subject) != -1) {
            theOne = i;
            console.log('Found alert email in position: ' + theOne);
        }
    }
    // the email should be in the list:
    expect(theOne).not.toBeUndefined();

});
}

function deleteAlertEmails() {

console.log('Deleting all emails');

var flow = protractor.promise.controlFlow()

var emails;

emails = element.all(by.repeater('email in emails')).all(by.binding('email.subject'));

emails.count().then(function(count) {
    console.log(count);

    for(var i=0; i&lt;count; i++) {           
        browser.waitForAngular();
        browser.driver.sleep(1000);
        emails = element.all(by.repeater('email in emails')).all(by.binding('email.subject'));

        emails.map(function (email) {
            return email;
        }).then(function (items) {
            items[0].click();

            // and some more waits after the click...
            browser.waitForAngular();
            browser.driver.sleep(2000);
            element(by.partialButtonText('Delete')).click();
        });
    }

   });



 }

describe('Referee', function() {
it('should send an email notification on failure of a check', function() {

    var flow = protractor.promise.controlFlow()

    var s3 = new AWS.S3();

    // start by deleting all old mails:
    console.log("0. First we delete all emails from the inbox");
    deleteAlertEmails();


    // First delete the file that is in S3, so the check will fail
    console.log("1. Now delete the file from S3");
    flow.await(deleteFile(s3)).then(function() {
        console.log('File deleted');
        // Wait for 1.5 minute to give it time to see that the file is not there and send a mail
        console.log("waiting for the DOWN mail...");

        // using browser.wait(condition)
        flow.await(browser.driver.sleep(60000)).then(function() {

            console.log("waited");
            // wait for angular:
            browser.waitForAngular();
            console.log("angular ready");

            // Search for the alert email:
            console.log("2. Search for the alert email");
            findEmailBySubject("DOWN - An S3 test file");

            // Now put the file back:
            console.log("3. Now put the file back");
            flow.await(uploadFile(s3)).then(function() {
                console.log("Successfully uploaded data to " + BUCKET_NAME + "/" + FILE_NAME);
  //                    // wait 15 seconds
 //                    browser.driver.sleep(15000);

                console.log("waiting for the UP mail...");
                // wait to make sure the UP email is sent
                flow.await(browser.driver.sleep(60000)).then(function() {


                // Search for the alert email:
                console.log("4. Search for the UP email");
                findEmailBySubject("UP - An S3 test file");

                // and now delete all the alert emails:
                console.log("5. Now delete all the emails from the inbox");
                deleteAlertEmails();

                });

            }, function(err) {
                console.log("ERROR uploading file to S3");
                throw new Error(err);
            });
        });


    }, function(err) {
        console.log('ERROR deleting file - stopping here');
        console.log(err);
        throw new Error(err);
    });


   });




   });
</code></pre>

<p>This is my local-config.js file:</p>

<pre><code> exports.config = {
 seleniumAddress: '',
 specs: ['down-mail.js'],
 onPrepare: function() {
 browser.driver.get('http://www.mailinater.com/inbox.jsp?to=juanazensie');
 },
 jasmineNodeOpts: {
 onComplete: null,
 isVerbose: true,
 showColors: true,
 includeStackTrace: true,
 defaultTimeoutInterval: 360000
 }
};
</code></pre>

<p>I would like to know please if is it possible to do this with the Gmail API and read these mails from Gmail using Protractor?</p>

<p>Thank you very much!!!</p>