从量角器中读取Gmail

时间:2016-04-04 11:42:52

标签: angularjs email gmail protractor

我有一个量角器测试,使用mailinator检查我是否收到了一些邮件,但我想改用Gmail。

我的测试看起来像这样:

在我的down-mail.js:

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 < 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<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);
    });


   });




   });

这是我的local-config.js文件:

 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
 }
};

我想知道是否可以使用Gmail API执行此操作并使用Protractor从Gmail中读取这些邮件?

非常感谢!!!

0 个答案:

没有答案