我正在尝试使注册页面自动化。进行注册时会收到一封激活邮件。我想在gmail上自动执行该激活邮件,例如当激活邮件出现时,它将自动单击该激活邮件并进行激活。
我需要测试一个量角器测试用例,在该用例中,用户注册,接收电子邮件,单击电子邮件中提供的激活按钮并设置密码。
问题是:如何单击该邮件。我的电子邮件有一个激活按钮。
我正在使用邮件监听器,但得到
错误:超时-未在由指定的超时内调用异步回调
jasmine.DEFAULT_TIMEOUT_INTERVAL
activationEmail.js
describe("Activation Email",function(){
var verify = new activateEmail();
function getLastEmail() {
var deferred = protractor.promise.defer();
console.log("Waiting for an email...");
mailListener.on("mail", function(mail){
deferred.fulfill(mail);
});
return deferred.promise;
};
it("verfying the email", function()
{
var verify = new activateEmail();
browser.ignoreSynchronization = true;
verify.getUrl();
console.log("URL Launch");
verify.setEmail("email");
console.log("enter email");
verify.clickNext();
console.log("click on next");
verify.setPassword("password");
console.log("enter password");
verify.clickNext();
console.log("Click on next");
verify.clickMailIcon();
});
it("find the mail", function(){
browser.ignoreSynchronization = true;
browser.wait(getLastEmail()).then(function (email) {
expect(email.subject).toContain("subject of email");
console.log("got subject");
expect(email.headers.to).toEqual("header of gmail");
console.log("got header");
// extract registration code from the email message
var pattern = /Registration code is: (\w+)/g;
var regCode = pattern.exec(email.text)[1];
console.log("got button")
console.log(regCode);
});
});
});
config.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine',
specs: ['./spec/activationEmail.js'],
onPrepare: function () {
var MailListener = require("mail-listener2");
// here goes your email connection configuration
var mailListener = new MailListener({
username: "username",
password: "password",
host: "imap.gmail.com",
port: 993, // imap port
tls: true,
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX", // mailbox to monitor
searchFilter: ["UNSEEN", "FLAGGED"], //
markSeen: true,
fetchUnreadOnStart: true,
mailParserOptions: {streamAttachments: true},
attachments: true,
attachmentOptions: { directory: "attachments/" }
});
mailListener.start();
mailListener.on("server:connected", function(){
console.log("Mail listener initialized");
});
global.mailListener = mailListener;
},
onCleanUp: function () {
mailListener.stop();
}
};
预先感谢